maven:如何使用“jar”中的jar导出打包的源代码;一揽子计划;阶段
我有一个maven导出脚本(不是我写的),我也想添加源代码。 构建脚本使用“maven源插件”生成2个输出: .jar和-sources.jar,它们彼此相邻地存在于同一输出文件夹中。 到目前为止,只复制了jar,我希望脚本将-sources.jar文件放在它的jar文件旁边 构建pom:maven:如何使用“jar”中的jar导出打包的源代码;一揽子计划;阶段,maven,Maven,我有一个maven导出脚本(不是我写的),我也想添加源代码。 构建脚本使用“maven源插件”生成2个输出: .jar和-sources.jar,它们彼此相邻地存在于同一输出文件夹中。 到目前为止,只复制了jar,我希望脚本将-sources.jar文件放在它的jar文件旁边 构建pom: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instan
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.mytest</groupId>
<artifactId>my-parent</artifactId>
<version>6.0.00-SNAPSHOT</version>
<packaging>pom</packaging>
<name>my-parent</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<assembly.format>dir</assembly.format>
<my.repository.rootUrl>http://maven.my.com</my.repository.rootUrl>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
.
.
.
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<target>1.6</target>
<source>1.6</source>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<modules>
.
.
.
</modules>
<repositories>
.
.
.
</repositories>
<distributionManagement>
.
.
.
</distributionManagement>
<pluginRepositories>
.
.
.
</pluginRepositories>
<organization>
<name>My</name>
</organization>
<profiles>
<profile>
<id>dist</id>
<modules>
<module>../my-assembly/my-runner</module>
</modules>
</profile>
</profiles>
</project>
4.0.0
org.mytest
我的父母
6.0.00-快照
聚甲醛
我的父母
http://maven.apache.org
UTF-8
迪尔
http://maven.my.com
朱尼特
朱尼特
.
.
.
org.apache.maven.plugins
maven编译器插件
2.5.1
1.6
1.6
UTF-8
org.apache.maven.plugins
maven源插件
2.2
附加来源
罐子
.
.
.
.
.
.
.
.
.
.
.
.
我的
距离
../my assembly/我的跑步者
出口pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mytest</groupId>
<artifactId>my-parent</artifactId>
<version>6.0.00-SNAPSHOT</version>
<relativePath>../../my-parent</relativePath>
</parent>
<artifactId>my-runner</artifactId>
<dependencies>
.
.
.
</dependencies>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>single</goal>
</goals>
<id>create-runner</id>
<phase>package</phase>
<configuration>
<finalName>runner</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/runner.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<formats>
<format>tar.gz</format>
<format>zip</format>
<format>dir</format>
</formats>
<id>runner</id>
<dependencySets>
.
.
.
<dependencySet>
<outputDirectory>lib</outputDirectory>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension} </outputFileNameMapping>
<includes>
<include>org.mytest:*:jar</include>
<include>org.mytest.systemobjects:*:jar</include>
</includes>
<excludes>
<exclude>*:my-services-so:*</exclude>
<exclude>*:my-services-tests:*</exclude>
<exclude>*:my-runner:*</exclude>
</excludes>
</dependencySet>
</dependencySets>
<fileSets>
.
.
.
</fileSets>
</assembly>
4.0.0
org.mytest
我的父母
6.0.00-快照
我的父母
我的跑步者
.
.
.
罐子
maven汇编插件
2.3
单一的
创建跑步者
包裹
跑步者
假的
src/main/assembly/runner.xml
运行程序文件(由导出pom引用):
tar.gz
拉链
迪尔
跑步者
.
.
.
解放党
${artifact.artifactId}.${artifact.extension}
org.mytest:*:jar
org.mytest.systemobjects:*:jar
*:我的服务是:*
*:我的服务测试:*
*:我的跑步者:*
.
.
.
提前谢谢你 从外观上看,似乎在每个阶段,孩子的插件都会先于家长的插件执行
您的父POM在包阶段(如果没有在执行中明确指定,这是源插件的默认阶段)指定源插件(生成源JAR),但在汇编插件中指定,它生成项目的tar.gz、zip和未压缩的完成版本,在源插件之前运行,因为程序集插件在子插件中声明,而源插件在父插件中声明
一个解决方案是更改源插件运行的阶段,以确保它在汇编插件之前运行,在包
阶段之前的某个阶段,例如准备包
将起作用。(生命周期阶段的完整列表如下所示)
在父级中,显式地将阶段设置为prepare package
,将使其:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>prepare-package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven源插件
2.2
附加来源
准备包装
罐子
这将强制源插件在程序集插件之前执行,因此程序集插件现在应该拾取两个连接的jar。使用
源添加另一个包含元素:
<include>org.mytest:*:jar:sources</include>
org.mytest::jar:sources
请参阅文档:插件的执行顺序是什么?源插件是在汇编插件之前还是之后执行的(注意到它们都处于包
阶段)?不确定Maven中关于执行顺序的规则和在父POMs中声明的插件,但是如果程序集插件首先执行,它将看不到源JAR,因为它还没有被附加。