首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用maven-bundle-plugin包含源包

如何使用maven-bundle-plugin包含源包
EN

Stack Overflow用户
提问于 2016-06-13 09:16:47
回答 1查看 1.5K关注 0票数 0

我使用maven - bundle插件将一些非OSGi maven jars重新打包为bundle。重新打包是基于包的嵌入式依赖特性,但直到今天,我还没有找到一种方法来包含该包的源代码。是否有方法获取所有已发布的依赖jar的源jar(聚合)?

显然,只有当maven中心有源jar可用时,才能使用源jar。

编辑谢谢@balazsz的钩子。我的最后一个解决方案来自于this response中的建议

代码语言:javascript
复制
<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文件

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2016-06-15 20:40:35

通过指定依赖项的分类器,始终可以将依赖项的源添加到项目中。例如:

代码语言:javascript
复制
<dependency>
    <groupId>com.j256.simplejmx</groupId>
    <artifactId>simplejmx</artifactId>
    <version>${project.version}</version>
    <classifier>sources</classifier>
</dependency>

由于源jar没有OSGi Manifest条目,所以maven-bundle插件对内部的内容不感兴趣。由于它是项目的依赖项,因此可以使用嵌入依赖指令将源工件嵌入到生成的包中。例如:

代码语言:javascript
复制
<configuration>
  <instructions>
    <Embed-Dependency>*;classifier=sources</Embed-Dependency>
  </instructions>
</configuration>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37785927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档