【问题标题】:How can I run two gmaven scripts in one pom.xml?如何在一个 pom.xml 中运行两个 gmaven 脚本?
【发布时间】:2017-04-06 04:22:27
【问题描述】:

我想从 maven 运行两个脚本,其中一个依赖于环境变量。我正在尝试这样的事情:

<build>
 <plugins>
  <plugin>
    <groupId>org.codehaus.groovy.maven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.0</version>
    <executions>
      <execution>
        <phase>validate</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <source>
            println "My script"
          </source>
        </configuration>
      </execution>
    </executions>
  </plugin>
</build>

...

<profile>
  <activation>
    <property>
      <name>env.MY_ENV_VAR</name>
      <value>runStuff</value>
    </property>
  </activation>
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.groovy.maven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <phase>validate</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                 println "My conditional script" 
              </source>
            </configuration>
          </execution>
        </executions>
      </plugin>          
    </plugins>
  </build>
</profile>

当我运行“mvn validate”来测试它时,我得到了“我的脚本”。当我设置环境变量并再次运行它时,我得到“我的条件脚本”但 not“我的脚本”。似乎如果条件满足,第二个运行,第一个不会。

我想无条件地运行第一个只有在设置了 env 变量的情况下才运行第二个。根据this question,我想过检查脚本本身中的 env 变量,但这似乎也有问题。

我是 maven 新手,所以不太可能有一个简单的解决方案,但我没有看到它。

【问题讨论】:

    标签: maven gmaven-plugin


    【解决方案1】:

    我找到了答案。每个执行都必须有一个唯一的 ID。如果您不指定 ID,则两者都为“默认”。一旦我给条件一个非默认 ID,它们都会运行。

    <build>
     <plugins>
      <plugin>
        ...
        <executions>
          <execution>
            <id>Unconditional-script</id>
            ...
          </execution>
        </executions>
      </plugin>
    </build>
    
    ...
    
    <profile>
      ...
      <build>
        <plugins>
          <plugin>
            ...
            <executions>
              <execution>
                <id>Conditional-script</id>
                ...
              </execution>
            </executions>
          </plugin>          
        </plugins>
      </build>
    </profile>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-21
      • 1970-01-01
      相关资源
      最近更新 更多