1

我收到以下错误。是因为install_path没有设置吗?如果是这样,这是否意味着在使用配置文件时,默认插件没有被执行(设置 的那个install_path)?

执行

mvn clean install site -Pfull

错误

无法在项目 bo-full 上执行目标 org.apache.maven.plugins:maven-clean-plugin:2.5:clean (clean-deploy-folder):缺少文件集的基本目录:null(包括:[],排除: [])

家长

<project>
    <plugins>
        <plugin>
            <!-- Workaround maven not being able to set a property conditionally based on environment variable -->
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <exportAntProperties>true</exportAntProperties>
                        <target>
                            <property environment="env"/>
                            <condition property="install.path" value="${env.SERVER_HOME}" else="C:\MY_SERVER">
                                <isset property="env.SERVER_HOME" />
                            </condition>
                            <echo message="${install.path}"/>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>
...

孩子

<project>
    <profiles>
        <profile>
            <id>full</id>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-clean-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>clean-deploy-folder</id>
                                <phase>pre-site</phase>
                                <goals>
                                    <goal>clean</goal>
                                </goals>
                                <configuration>
                                    <excludeDefaultDirectories>true</excludeDefaultDirectories>
                                    <filesets>
                                        <fileset>
                                            <directory>${install.path}</directory>
                                        </fileset>
                                    </filesets>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
...
4

1 回答 1

0

1) 即使使用配置文件,也应执行默认插件。请通过以下构建日志验证是否发生这种情况 - 每个插件执行都由 maven 记录,即使插件本身没有记录任何内容。

2) 您应该在与创建属性的执行相同的 Maven 项目/模块中执行清理。一个原因是您的子模块可以单独构建(如果可用,它将使用来自本地/远程存储库的父 pom.xml)。无论出于何种原因,属性也有可能在反应堆构建中没有正确传播。

3)如果问题确实是属性传播并且 antrun 插件有问题,您可以用 Maven 配置文件替换您的 antrun 执行。它应该是这样的:

<properties>
  <!-- default value goes here: -->
  <install.path>C:\MY_SERVER</install.path>
</properties>

<profiles>
  <profile>
    <id>env</id>
    <activation>
      <property>
        <!-- activate this profile when property is specified: -->
        <name>env.SERVER_HOME</name>
      </property>
    </activation>
    <properties>
      <!-- override default property value: -->
      <install.path>${env.SERVER_HOME}</install.path>
    </properties>
  </profile>
</profiles>
于 2016-05-23T12:52:45.010 回答