2014-10-15 3 views
1

다음 동작을 원합니다 : "my.prop"속성 값을 지정할 때 의존성 및 클린 플러그인을 실행하고 싶습니다. 해당 속성에 값이 지정되지 않은 경우 해당 속성을 건너 뛰기를 원합니다. Maven - 속성이 비어있는 경우 플러그인 건너 뛰기

<properties> 
    <my.prop></my.prop> 
</properties> 

가 그럼 난 프로필 활성화가 시스템 속성에 대해서만 작동 읽기, 그래서 확실한 플러그인 위의 삭제 및 사용 :

는이 같은 "my.prop"를 만들어

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-surefire-plugin</artifactId> 
    <version>2.17</version> 
    <configuration> 
     <systemPropertyVariables> 
      <my.prop></my.prop> 
     </systemPropertyVariables> 
    </configuration> 
</plugin> 
을 내가 뭔가 리튬을 각 플러그인,

<profiles> 
    <profile> 
     <id>default</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <properties> 
      <skipDependecyAndCleanPlugins>false</skipDependecyAndCleanPlugins> 
     </properties> 
    </profile> 
    <profile> 
     <id>skip-dependency-and-clean-plugins</id> 
     <activation> 
      <property> 
       <name>my.prop</name> 
       <value></value> 
       <!-- I also tried: <value>null</value> without success.--> 
      </property> 
     </activation> 
     <properties> 
      <skipDependecyAndCleanPlugins>true</skipDependecyAndCleanPlugins> 
     </properties> 
    </profile> 
</profiles> 

나중에 :

나는이 같은 프로파일을 사용하여 시도 KE이 : ​​

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.9</version> 
    <configuration> 
     <skip>${skipDependecyAndCleanPlugins}</skip> 
    </configuration> 
    .... 
</plugin> 

하지만 플러그인은 여전히 ​​실행 ...

이 어떻게 널 (null)/비어있을 때 "my.prop"플러그인의 실행을 건너 메이븐을 확인할 수 있습니까?

+0

먼저 quenstion를 건너 뜁니다

mvn ... -Dmy.prop=true 

가 : 당신은 왜 그런 행동을해야합니까? 성취하고자하는 것을 조금 더 자세히 설명해 주실 수 있습니까? – khmarbaise

+0

Oxygen XML Editor 플러그인으로 작업하고 있습니다. 그리고 내가 원하는 것은 사용자가 [OXY_DIR]/plugins에 대한 경로를 지정하면 플러그인이 자동으로 배포된다는 것입니다. 이를 위해 2 개의 플러그인을 실행해야합니다. 사용자가 "my.prop"을 비워두면 플러그인을 배치하는 플러그인을 실행하면 안됩니다. –

+0

프로필을 사용하고 ** 속성을 사용하지 않는 것이 좋습니다 **. 따라서'mvn -Pxyz install' 명령 행에서 정의하거나 그대로 둘 수 있습니다. – khmarbaise

답변

3

가장 간단한 솔루션은 다음과 같은 형태로 활성화를 사용하는 것입니다 :

<profiles> 
    <profile> 
    <activation> 
     <property> 
     <name>debug</name> 
     </property> 
    </activation> 
    ... 
    </profile> 
</profiles> 

가 위의 당신이 -Ddebug 충분히 의미 디버그에 대한 값을 정의 할 수 있음을 의미합니다.

빈 값을 pom 파일로 정의 할 수 없습니다. <value></value>은 정의되지 않았 음을 의미하는 <value/>과 같습니다.

업데이트 : 프로파일이 아닌 속성을 사용하는 것이 좋습니다 것입니다

. 따라서 mvn -Pxyz 커맨드 라인에서 간단히 정의하거나 설치할 수 있습니다.

+0

-Dmy.prop를 사용하여 값을 전달한다면, 나는 pom.xml에 어떻게 든 선언 할 필요가있다. 내가 게시 한 처음 2 단편과 관련이 있습니까? 나는 그들 중 어느 것이 필요합니까? –

0

당신은 플러그인의 구성에 my.prop 속성을 사용할 수 있습니다 :

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-dependency-plugin</artifactId> 
    <version>2.9</version> 
    <configuration> 
     <skip>${my.prop}</skip> 
    </configuration> 
    .... 
</plugin> 

을 이제 실행할 때 : 다음 플러그인이

+0

정말로 ... my.prop는 파일 경로를 포함해야합니다 ... 나쁜 속성 이름의 전형적인 예입니다. –