将所有maven依赖项从children pom复制到目录

时间:2014-07-16 14:10:51

标签: java maven maven-dependency-plugin

我正在尝试将项目及其子模块的所有依赖项复制到特定文件夹(假设为parent / target / lib)

项目是这样的:

parent
|- module1
|- module2    
|- module3
   |- module3.1
   |- module3.2
|- module4

在我的理解中,唯一的方法是在每个子模块中使用maven copy-dependency,如下所示:

<execution>
    <id>copy-dependencies</id>
    <phase>package</phase>
    <goals>
        <goal>copy-dependencies</goal>
    </goals>
    <configuration>
        <includeScope>runtime</includeScope>
        <outputDirectory>${parent.dir}/target/lib</outputDirectory>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>false</overWriteSnapshots>
        <overWriteIfNewer>true</overWriteIfNewer>
        <excludeGroupIds>xerces</excludeGroupIds>
        <excludeArtifactIds>junit,testng,easymock</excludeArtifactIds>
    </configuration>
</execution>

我遇到了很多问题:

  1. lib文件夹将包含工件的所有版本(我只想要最新版本)
  2. 对于每个包含/排除规则,所有的poms都需要更新(有很多)
  3. 是否有与依赖项一起工作的东西:list来获取所有依赖项,保留最新的并将它们复制到我的/ lib文件夹?

1 个答案:

答案 0 :(得分:0)

我最终在一个新的子项目中使用了程序集插件,如下所示:

parent
|- module1
|- module2    
|- module3
   |- module3.1
   |- module3.2
|- module4
|- assembly-module

assembly-module调用maven-assembly-plugin(pom.xml):

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptor>src/assembly/bin.xml</descriptor>
                <finalName>module-assembly</finalName>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

最后我的程序集文件看起来像这样(assembly-module / src / assembly / bin.xml)

<id>bin</id>
<formats>
    <format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>

<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
        <scope>runtime</scope>
        <useProjectArtifact>false</useProjectArtifact>
        <includes/>
        <excludes>
            <exclude>org.eclipse.jdt:core</exclude>
        </excludes>
    </dependencySet>
</dependencySets>