2011-09-12 37 views
1

我正在使用Maven 3.0.3。我有一个项目,从父母继承...Maven:只想运行配置文件,如果在父pom上构建的话

<modelVersion>4.0.0</modelVersion> 
    <groupId>com.myco.util.ant</groupId> 
    <artifactId>selenium-framework</artifactId> 
    <packaging>jar</packaging> 
    <name>Myco Selenium Utils</name> 
    <parent> 
      <groupId>com.nna</groupId> 
      <artifactId>parent</artifactId> 
      <version>1.2-SNAPSHOT</version> 
      <relativePath>../parent</relativePath> 
    </parent> 

在我父母pom我有以下配置文件。但是,如果有人正在对父项目进行构建,而不是其中的一个子项目,我只希望此配置文件保持活跃状态​​。有谁知道我可以如何调整下面的内容,以便在有人正在构建子项目时不会激活它?

  <profile> 
        <id>deploy-snapshot</id> 
        <build> 
          <plugins> 
            <plugin> 
              <artifactId>maven-antrun-plugin</artifactId> 
              <version>1.6</version> 
              <executions> 
                <execution> 
                  <phase>deploy</phase> 
                  <configuration> 
                    <target> 
                      <condition property="is-release"> 
                        <not> 
                          <contains string="${project.version}" substring="SNAPSHOT" /> 
                        </not> 
                      </condition> 
                      <fail if="is-release" message="You can only deploy snapshot versions of this project." /> 
                    </target> 
                  </configuration> 
                  <goals> 
                    <goal>run</goal> 
                  </goals> 
                </execution> 
              </executions> 
            </plugin> 
          </plugins> 
        </build> 
        <activation> 
          <activeByDefault>true</activeByDefault> 
        </activation> 
      </profile> 

谢谢 - 戴夫

回答

0

你可以尝试通过存在/不存在一个文件或目录的激活它。你可以找到一个example in the Sonatype Maven book。请注意,“当前工作目录”和“${project.basedir}”之间存在差异,如果这对您很重要,Maven 2和Maven 3之间的差异略有不同。

+0

感谢有关基于文件存在的配置文件激活的想法,但我的父项目只有一个pom.xml文件和目标目录,不足以(仅基于这些文件)将其与子项目区分开来。任何其他想法? - – Dave

+1

@Dave。你总是可以将目录(和/或文件)添加到“pom”项目中。 –

0

我有类似的情况,我想在默认情况下在子项目中运行配置文件,但不是在从顶层构建时运行配置文件,同时也提供从顶层项目运行它的选项。

我用user.dir属性结合Ryan的参考。

整合项目的POM:

<profile> 
     <id>continuous-integration</id> 
     <!-- Two ways of activating this profile --> 
     <activation> 
      <!-- Run the build from the top with param -DfullTest --> 
      <property> 
       <name>fullTest</name> 
      </property> 
      <!-- Run the build from the integration directory --> 
      <file> 
       <missing>${user.dir}/integration</missing> 
      </file> 
     </activation> 
    ... 
    <profile> 

如果被禁用的需求只是改变<missing/><exists/>

相关问题