0

我有以下 maven pom.xml

<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org  /2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc.def.ghi</groupId>
<artifactId>core-with-releases</artifactId>
<version>1</version>
<properties>
<yum-repo>/var/www/html/core-repo</yum-repo>
</properties>
<organization>
<name>ABC DEF GHI</name>
</organization>
<dependencyManagement>
<dependencies>
  <dependency>
    <groupId>com.aaa.bbb.ccc.ddd</groupId>
    <artifactId>core</artifactId>
    <version>1.1.3</version>
    <type>rpm</type>
  </dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
      <execution>
        <id>create-directory</id>
        <phase>process-resources</phase>
        <goals>
          <goal>exec</goal>
        </goals>
        <configuration>
          <executable>mkdir</executable>
          <arguments>
            <argument>${yum-repo}${dependencies["com.aaa.bbb.ccc.ddd:core"].version}</argument>
          </arguments>
        </configuration>
      </execution>
    </executions>
  </plugin>
 </plugins>
 </build>
 </project>

我从命令行执行

mvn clean process-resources

因此,我希望创建目录,其名称以依赖项管理元素中的工件版本结尾,即 1.1.3

有人可以帮忙吗?谢谢。

4

1 回答 1

1

我建议将属性用于此类目的:

<properties>
  <yum-repo>/var/www/html/core-repo</yum-repo>
  <dep.groupId>com.aaa.bbb.ccc.ddd</dep.groupId>
  <dep.artifactId>core</dep.artifactId>
  <dep.version>1.1.3</dep.version>
</properties>
<organization>
<name>ABC DEF GHI</name>
</organization>
<dependencyManagement>
<dependencies>
  <dependency>
    <groupId>${dep.groupId}</groupId>
    <artifactId>${dep.artifactId}</artifactId>
    <version>${dep.version}</version>
    <type>rpm</type>
  </dependency>
</dependencies>
  ...
        <configuration>
          <executable>mkdir</executable>
          <arguments>
            <argument>${yum-repo}${dep.version}</argument>
          </arguments>
        </configuration>
      </execution>
    </executions>
  ...

您应该知道,通过在dependencyManagement中定义一个依赖项,该依赖项将不会被绑定为您当前项目的依赖项。

于 2012-05-03T08:08:09.057 回答