Is it possible to set a maven property from ant?

浪子不回头ぞ 提交于 2019-12-04 03:38:14

As of version 1.7 of the maven-antrun-plugin it is possible according to the plugin documentation (see exportAntProperties). So, I guess, in earlier versions: it's not ;-).

you can redirect your strategy to activation of different profiles depending on the existence of the file instead of antrun-plugin:

<profiles>
    <profile>
        <id>notExist</id>
        <activation>
          <file>
            <missing>target/maven-archiver/notExist.properties</missing>
          </file>
        </activation>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

<profile>
    <id>exist</id>
    <activation>
      <file>
        <exists>target/maven-archiver/pom.properties</exists>
      </file>
    </activation>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.3</version>
                <executions>
                  <execution>
                    <phase>package</phase>
                    <goals>
                      <goal>run</goal>
                    </goals>
                    <configuration>
                        <tasks>
                            <echo>not exist</echo>
                        </tasks>
                    </configuration>
                  </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

You can use activation profiles maven features to distinguish between one configuration and another according the activation criteria.

I use the antrun-plugin in example only for do the echo

Yes, with even a default value. Example setting install.path with echo:

<plugin>
    <!-- Workaround maven not being able to set a property conditionally based on environment variable -->
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <exportAntProperties>true</exportAntProperties>
                <target>
                    <property environment="env"/>
                    <condition property="install.path" value="${env.INSTALL_HOME}" else="C:\default-install-home">
                        <isset property="env.INSTALL_HOME" />
                    </condition>
                    <echo message="${install.path}"/>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!