我使用maven-bundle-plugin将一些非OSGi maven jar重新打包为bundle。 重新打包是基于该捆绑包的嵌入依赖性功能,但直到今天我还没有找到一种方法来包含该捆绑包的来源。 有没有办法获得所有emdedded依赖jar的源jar(聚合)?
显然只有在maven中心可以使用源jar。
编辑感谢@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://git@github.com/j256/simplejmx.git</connection>
<developerConnection>scm:git:ssh://git@github.com/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>
答案 0 :(得分:0)
您始终可以通过指定分类器将依赖项源添加到项目中。 E.g:
<dependency>
<groupId>com.j256.simplejmx</groupId>
<artifactId>simplejmx</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
</dependency>
由于源jar没有OSGi Manifest条目,maven-bundle-plugin对内部的内容不感兴趣。由于它是项目的依赖项,因此可以使用Embed-Dependency指令将sources工件嵌入到生成的bundle中。 E.g:
<configuration>
<instructions>
<Embed-Dependency>*;classifier=sources</Embed-Dependency>
</instructions>
</configuration>