Maven如何从项目执行情况汇总来源 [英] Maven how to aggregate source from project depedencies

查看:89
本文介绍了Maven如何从项目执行情况汇总来源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用maven-bundle-plugin从非osgi依赖创建osgi插件,我想将来自这个pedentiency的源包含在projet版本中.

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.

这是一个示例,我从jfreechart创建了一个OSGI包,发布时我想包含jfreechart源.

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>

推荐答案

我遇到了同样的问题.这就是我最终要做的事情:

I had the same issue. Here's what I ended up doing:

  1. 使用maven-dependency-plugin来解压缩源

  1. unpack the sources using the maven-dependency-plugin

<plugin>
  <artifactId>maven-dependency-plugin</artifactId>
  <executions>
    <execution>
      <id>unpack-sources</id>
      <goals>
        <goal>unpack</goal>
      </goals>
      <configuration>
        <outputDirectory>${project.build.directory}/sources</outputDirectory>
        <artifactItems>
          <artifactItem>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
            <classifier>sources</classifier>
          </artifactItem>
        </artifactItems>
      </configuration>
    </execution>
  </executions>
</plugin>

  • 附加使用maven-assembly-plugin构建的源工件

  • attach a sources artifact built with the maven-assembly-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>
    

    具有以下描述符(请注意,描述符id用作分类器;默认情况下附加工件):

    with the following descriptor (note that the descriptor id is used as the classifier ; the artifact is attached by default):

    <?xml version="1.0"?>
    <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>
    

  • 这篇关于Maven如何从项目执行情况汇总来源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆