从Ant代码导出Maven属性

Gil*_*ili 5 ant maven-2

我在POM中嵌入了以下代码:

<plugin name="test">
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
      <executions>
        <execution>
          <phase>validate</phase>
            <configuration>
              <tasks>
                <pathconvert targetos="unix" property="project.build.directory.portable">
                  <path location="${project.build.directory}"/>
                </pathconvert>
              </tasks>
            </configuration>
          <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

然后我${project.build.directory.portable}run project动作中引用但它又回来了null.<echo>在Ant块中执行显示正确的值.我究竟做错了什么?

Alb*_*rto 11

为了完整起见,上述功能maven-antrun-plugin2010年10月实施.

您正在寻找的配置参数是exportAntProperties.

使用示例:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7-SNAPSHOT</version>
    <executions>
        <execution>
            <phase>process-resources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <exec outputproperty="svnversion"
                        executable="svnversion">
                        <arg value=".." />
                    </exec>
                </target>
                <exportAntProperties>true</exportAntProperties>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

作为旁注,在本文(2011-10-20)时,官方插件文档没有记录此选项.要获得插件的'versionXYZ'的帮助:

mvn help:describe -Dplugin=org.apache.maven.plugins:maven-antrun-plugin:versionXYZ -Ddetail
Run Code Online (Sandbox Code Playgroud)

  • 我注意到这不会覆盖 POM 中已经声明的属性,但是如果我不声明该属性,我的 linter(使用 IntelliJ)会抱怨未知的属性符号。有没有办法告诉它忽略这个,或者告诉插件覆盖现有的属性? (2认同)

nur*_*eta 5

maven-antrun-plugin 的 1.7 版本帮助我将属性从 ant 传递到 maven(以及从 mvn 到 ant)。一些示例代码,计算文件的 md5 校验和,然后将其存储到稍后由 mvn 访问的属性中:

<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
    <execution>
        <id>ant-md5</id>
        <phase>initialize</phase>
        <goals>
        <goal>run</goal>
        </goals>
    <configuration>

<target>
    <property name="compile_classpath" refid="maven.compile.classpath"/>
    <property name="outputDir" value="${project.build.outputDirectory}"/>
    <property name="sourceDir" value="${project.build.sourceDirectory}"/>
    <checksum  file="${sourceDir}/com/blah/db/blah.java" property="blah.md5db"/>
</target>
<exportAntProperties>true</exportAntProperties>
</configuration>
</execution>
</executions>
Run Code Online (Sandbox Code Playgroud)

稍后可以通过 java 文件中的 ${blah.md5db} 访问该属性。