如何从maven pom中的dependencyManagement引用工件版本

时间:2012-05-02 18:32:51

标签: maven-3

我有以下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

因此,我希望创建目录,其名称以dependencyManagement元素1.1.3中的工件版本结尾

有人可以帮忙吗?感谢。

1 个答案:

答案 0 :(得分:0)

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

<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 中定义依赖关系,依赖关系将绑定为当前项目的依赖关系。