Maven:只复制构建jar而不是构建poms

时间:2017-03-29 08:14:45

标签: java maven

我有以下maven结构:

ParentProject
|-project-1
| |-src
| |-pom.xml
|-project-N
| |-src
| |-pom.xml
|-pom.xml 

在父项目pom中,我使用以下插件进行复制:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.6</version>
    <executions>
    <execution>
        <id>copy</id>
        <phase>package</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                  <groupId>${project.groupId}</groupId>
                  <artifactId>${project.artifactId}</artifactId>
                  <version>${project.version}</version>
                  <type>${project.packaging}</type>
                  <outputDirectory>/somepath/jars</outputDirectory>
                </artifactItem>
            </artifactItems>
        </configuration>
        </execution>
    </executions>
</plugin>

我在父项目pom中使用此插件但不在project-1 / N中使用此插件,因为我不想使用此插件和输出目录进行复制(在某些情况下,可以有一个目录,在相同情况下可以有几个目录)。该插件运行良好。但是,它也复制了构建父项目pom。如何在没有父项目pom的情况下仅复制项目1 / N罐?

1 个答案:

答案 0 :(得分:1)

实现目标的一种方法是在父级内部将skip添加到true:

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                    <skip>true</skip>
                        <artifactItems>
                            <artifactItem>
                                <groupId>${project.groupId}</groupId>
                                <artifactId>${project.artifactId}</artifactId>
                                <version>${project.version}</version>
                                <type>${project.packaging}</type>
                                <outputDirectory>${project.build.directory}/lib/</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>

然后在你的孩子中将其切换为假:

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <skip>false</skip>
                    </configuration>
                </execution>
            </executions>
         </plugin>