Maven 如何从项目依赖性中聚合源代码
我使用 maven-bundle-plugin 从非 osgi 依赖项创建 osgi 插件,并且我想将此依赖项的源代码包含到项目构建中。
这是我从 jfreechart 创建 OSGI 包的示例,当我发布它时,我想包含 jfreechart 源。
<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.jfree.chart</groupId>
<artifactId>com.netappsid.org.jfree.chart</artifactId>
<version>1.0.13</version>
<name>JFreeChart OSGI</name>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.jfree.chart.*;org.jfree.data.*</Export-Package>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Embed-Dependency>jfreechart;inline=true</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>com.springsource.org.jfree</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
</project>
I use maven-bundle-plugin to create osgi plugin from non osgi depedency and I want to include the source from this depedency into the projet build.
This is an example I create an OSGI bundle from jfreechart and when I publish it I want to include jfreechart sources.
<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.jfree.chart</groupId>
<artifactId>com.netappsid.org.jfree.chart</artifactId>
<version>1.0.13</version>
<name>JFreeChart OSGI</name>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.jfree.chart.*;org.jfree.data.*</Export-Package>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Embed-Dependency>jfreechart;inline=true</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>com.springsource.org.jfree</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
</project>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有同样的问题。这就是我最终所做的:
使用 maven-dependency-plugin 解压源代码
<前><代码><插件>;
maven-dependency-plugin ;
解包源
${project.build.directory}/sources
commons-httpclient ;
commons-httpclient ;
<处决>
<执行>
<目标>
<目标>解压
<配置>
<工件项目>
<工件项目>
<版本>3.1
<分类器>来源
附加使用 maven-assemble-plugin 构建的源工件
<前><代码><插件>;
maven- assembly-plugin ;
源程序集
<处决>
<执行>
<阶段>封装
<目标>
<目标>单个
<配置>
<描述符>
<描述符>src.xml
使用以下描述符(请注意,描述符 id 用作分类器;默认情况下会附加工件):
I had the same issue. Here's what I ended up doing:
unpack the sources using the maven-dependency-plugin
attach a sources artifact built with the maven-assembly-plugin
with the following descriptor (note that the descriptor id is used as the classifier ; the artifact is attached by default):
如果我理解正确的话...
我必须自己打包许多无 osgi 的 JAR 以便在 OSGi 应用程序中使用。使用
maven-bundle-plugin
时,如果您在清单(或osgi.bnd
文件)中使用Export-Package
,则其类将包含在创建的捆绑包中。示例:
这里,导出的包将包含在 POM 中我的 Maven 依赖项的 JAR 中。
如果您还想包含依赖项 JAR,那么您可以使用
Embed-Dependency
:如果这就是您正在寻找的内容?
托尼
If I understand you correctly...
I've had to package many osgi-less JARs myself for use in an OSGi application. When using the
maven-bundle-plugin
, if you are usingExport-Package
in the manifest (orosgi.bnd
file) then its classes will be included in the created bundle.Example:
Here, the exported packages will be included in the JAR from my Maven dependencies in the POM.
If you also want to include the dependency JAR, then you can use
Embed-Dependency
:If this what you were looking for?
Tony