我使用maven-bundle-plugin將一些非OSGi maven jar重新打包爲bundle。 重新包裝基於該包的Embed-Dependency特性,但直到今天我還沒有找到一種方法來包含該包的源。 有沒有一種方法來獲得所有emdedded的依賴jar的源jar(聚合)?如何使用maven-bundle-plugin包含源碼包
顯然只有源碼jar在maven中心可用。
編輯感謝@balazsz爲鉤子。 我的最終解決方案來自於建議this response
<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>com.example</groupId>
<artifactId>com.example.com.j256.simplejmx</artifactId>
<version>1.12</version>
<packaging>bundle</packaging>
<name>SimpleJMX</name>
<properties>
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<bundle.version>${project.version}.${maven.build.timestamp}</bundle.version>
</properties>
<licenses>
<license>
<name>ISC</name>
<url>https://www.isc.org/downloads/software-support-policy/isc-license/</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:ssh://[email protected]/j256/simplejmx.git</connection>
<developerConnection>scm:git:ssh://[email protected]/j256/simplejmx.git</developerConnection>
<url>https://github.com/j256/simplejmx</url>
</scm>
<dependencies>
<dependency>
<groupId>com.j256.simplejmx</groupId>
<artifactId>simplejmx</artifactId>
<version>${project.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
<profiles>
<profile>
<id>disable-java8-doclint</id>
<activation>
<jdk>[1.8,)</jdk>
</activation>
<properties>
<additionalparam>-Xdoclint:none</additionalparam>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<instructions>
<!-- includes all packages listed in Private-Package and exports those
listed in Export-Package -->
<Bundle-Version>${bundle.version}</Bundle-Version>
<Export-Package>com.j256.simplejmx.server;version=${project.version},
com.j256.simplejmx.common;version=${project.version},
com.j256.simplejmx.client;version=${project.version}
</Export-Package>
<Private-Package>!com.j256.simplejmx.spring.*,
!com.j256.simplejmx.web.*
</Private-Package>
<Import-Package>!com.j256.simplejmx.*,*</Import-Package>
</instructions>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-sources</id>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.j256.simplejmx</groupId>
<artifactId>simplejmx</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
<excludes>**/simplejmx/web/**,**/simplejmx/spring/**</excludes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>source-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.4</version>
<executions>
<execution>
<id>javadoc</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<sourcepath>${project.build.directory}/sources</sourcepath>
</configuration>
</plugin>
</plugins>
</build>
</project>
src.xml文件
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>sources</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/sources</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
如果你需要列出你想要的源代碼的依賴關係,這對你來說是個問題嗎?我可以展示一個例子,但是如果你想自動(和傳遞)地獲取這些罐子,則不能。 –
@balazs我使用主pom.xml編輯主要問題。我會這個maven進程也創建了源代碼com.j256.simplejmx – nfalco
的源代碼,我想我誤解了你。所以你想有一個項目,並將另一個項目的來源合併到你的項目中。如果您的項目也重新編譯了原始項目java文件,會不會是一個問題?我想我知道另一個解決方案,在這裏你使用maven-dependency-plugin來解壓其他的工件和maven-buildhelper-plugin,將解壓後的源文件添加到你的項目中。所有這些都在生成源代碼階段。之後,一切正常,你不需要使用Embed-Dependency指令。 –