【问题标题】:Are parent default plugins being executed when using a child profile in maven?在 Maven 中使用子配置文件时是否执行父默认插件?
【发布时间】:2016-09-20 05:28:12
【问题描述】:

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

执行:

mvn clean install site -Pfull

错误:

未能执行目标 org.apache.maven.plugins:maven-clean-plugin:2.5:clean 项目 bo-full 上的 (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>
...

【问题讨论】:

    标签: maven maven-clean-plugin


    【解决方案1】:

    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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      相关资源
      最近更新 更多