2011-07-27 2 views
17

Maven 3.0.3을 사용하고 있습니다. 스크립트 ("env")에 변수를 정의해야합니다. 나는 아무도가 "-P"로 지정되어 있지 않은 경우에만 프로필을 활성화 어떻게 내가 <profile> 요소마다 변수를 정의하는 내 치어의 <profiles> 섹션 ... 내 pom.xml 파일에서기본적으로 프로필 활성화

<profile> 
    <id>qa</id> 
    <properties> 
    <env>qa</env> 
    ... 
    </properties> 
</profile> 

을 가지고 명령 줄 옵션 (그리고 정의되지 않은 경우 변수를 설정)? 내가 설정 한 집행자 플러그인은 내가 "ENV"변수의 정의가 필요하기 때문에

<profile> 
    <id>dev</id> 
    <activation> 
    <activeByDefault>true</activeByDefault> 
    <property> 
     <name>env</name> 
     <value>dev</value> 
    </property> 
    </activation> 
    <properties> 
    <url>http://localhost:8080/manager</url> 
    <server>nnadbmon-dev-tomcat</server> 
    </properties> 
</profile> 

하지만 명령 "MVN 컴파일"실행이 실패, 아래 시도했다. 여기

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-enforcer-plugin</artifactId> 
    <version>1.0</version> 
    <executions> 
    <execution> 
     <id>enforce-property</id> 
     <goals> 
     <goal>enforce</goal> 
     </goals> 
     <configuration> 
     <rules> 
      <requireProperty> 
      <property>env</property> 
      <message>Environment missing. This should be either dev, qa, or prod, specified as part of the profile (pass this as a parameter after -P).</message> 
      <regex>^(dev|qa|production)$</regex> 
      <regexMessage>Incorrect environment. Expecting one of dev, qa, or prod.</regexMessage> 
      </requireProperty> 
     </rules> 
     <fail>true</fail> 
     </configuration> 
    </execution> 
    </executions> 
</plugin> 
+0

당신이 원하는 것은 분명하지 않습니다. 'env'속성에 대한 기본값을 제공 하시겠습니까? – bmargulies

+0

예, env 속성에 기본값을 제공하고 싶습니다. – Dave

+1

귀하의 집행자 구성을 게시하십시오. 실제로 'env'속성을 정의하지 않았습니다. 이러한 속성이 존재하고 특정 값이있는 경우 실행할 프로필을 설정하면됩니다. 기본 env 속성을 다른 값으로 속성 요소에 추가 할 수 있습니다. – bmargulies

답변

0

나는 당신이 나는 그것이 오래 전 알고 http://maven.apache.org/pom.html#Activation

+0

안녕하세요, 내 질문을 편집 (기본적으로 " true"추가),하지만 "-P"지시문을 남기면 내 빌드가 여전히 실패합니다 (왜냐하면 enforcer 플러그인이 "env"속성 찾기). Dave – Dave

+1

@Dave : mvn help : active-profiles을 입력하면 기본적으로 활성화되어있는 프로파일을 볼 수 있습니다. – Stephane

41

이다 싶은 생각에 대한 문서 ... 내 집행자 플러그인에 대한 실행 코드,하지만 난 그냥 지금이 문제를 가지고 있었다, 그래서 ... 당신은 그렇게해야합니다 :

<profile> 
    <id>dev</id> 
    <activation> 
     <activeByDefault>true</activeByDefault> 
    </activation> 
    <properties> 
     <env>dev</env> 
     <url>http://localhost:8080/manager</url> 
     <server>nnadbmon-dev-tomcat</server> 
    </properties> 
</profile> 
+5

참고 : 다른 활성화 규칙이나 -P 명령 줄을 통해 다른 프로필을 더 적극적으로 선택하면 activeByDefault 프로필이 선택되지 않습니다. –

관련 문제