2011-09-12 5 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> 

부모님의 프로필에는 다음과 같은 프로필이 있습니다. 그러나, 나는 누군가가 그 부모 중 한 명과는 반대로 부모 퐁에 빌드를하고있는 경우에만이 프로파일을 활성화하기를 원합니다. 다른 사람이 자식 프로젝트 빌드를 수행하는 경우 활성화되지 않도록 내가 어떻게 아래 조정할 수 있는지 아는 사람 있습니까?

  <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

필자는 비슷한 상황 이었지만, 기본적으로 하위 프로젝트에서 프로필을 실행하고 싶었지만 최상위 수준에서 빌드 할 때와 동시에 최상위 프로젝트에서 프로필을 실행하는 옵션을 제공하지 않았습니다.

나는 Ryan의 참조 조합에 대해 user.dir 속성을 사용했습니다. 통합 프로젝트의 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> 

단지 <exists/><missing/>을 변경합니다.

관련 문제