【问题标题】:Problem with picking up a -Dattribute in Maven using Antrun使用 Antrun 在 Maven 中获取 -Dattribute 的问题
【发布时间】:2011-04-12 11:08:05
【问题描述】:

所以我的 pom 中有这个 sn-p

<configuration>  
  <target if="csc" >
    <echo>Unzipping md csc help</echo>
  </target> 
  <target unless="csc">
    <echo>Unzipping md help</echo>
  </target>
</configuration>

当我正常使用 mvn 运行时,它会正确执行 unless="csc" 目标。问题是当我使用 -Dcsc=true 运行它时,它不会运行任何目标。

我做错了什么? :)

谢谢

【问题讨论】:

  • 不使用Ant也可以解压...

标签: maven-2 maven-antrun-plugin


【解决方案1】:

antrun 插件似乎只支持配置中的单个目标元素。您可以使用maven profiles 达到与property is set or absent 激活时相同的效果:

<profiles>
    <profile>
        <id>property-set</id>
        <activation>
            <property>
                <name>csc</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <id>antrun-property-set</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>generate-sources</phase>
                            <configuration>
                                <target> 
                                    <echo>property is set</echo>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>property-not-set</id>
        <activation>
            <property>
                <name>!csc</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-antrun-plugin</artifactId>
                    <version>1.6</version>
                    <executions>
                        <execution>
                            <id>antrun-property-not-set</id>
                            <goals>
                                <goal>run</goal>
                            </goals>
                            <phase>generate-sources</phase>
                            <configuration>
                                <target> 
                                    <echo>property is not set</echo>
                                </target>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

【讨论】:

    【解决方案2】:

    可以通过maven-dependency plugin进行解包。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 2022-02-03
      相关资源
      最近更新 更多