没有附带Maven-assembly-plugin的源jar [英] No source jar attached with maven-assembly-plugin

查看:87
本文介绍了没有附带Maven-assembly-plugin的源jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下项目maven(3.10)多项目:

I have the following project maven (3.10) multi project:

my-mvn
 -> my-mvn-a
 -> my-mvn-b
 -> my-mvn-assembly

my-mvn-amy-mvn-b使用以下命令构建源jar:

my-mvn-a and my-mvn-b build source jars using:

<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>
    <parent>
        <groupId>my.group</groupId>
        <artifactId>my-mvn</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>my-mvn-a</artifactId>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

my-mvn-assembly中,我想构建一个包含my-mvn-amy-mvn-b的jar和源jar的zip文件. pom.xml文件:

In my-mvn-assembly I would like to build a zip including jars and source jars from my-mvn-a and my-mvn-b. The pom.xml file:

<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>
    <parent>
        <groupId>my.group</groupId>
        <artifactId>my-mvn</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </parent>
    <artifactId>my-mvn-assembly</artifactId>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>${project.artifactId}-${project.version}</finalName>
                    <descriptors>
                        <descriptor>src/main/resources/my_assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>my.group</groupId>
            <artifactId>my-mvn-a</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

和描述符:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <id>my-assembly</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <includes>
                <include>my.group:my-mvn-a:jar:${project.version}</include>
                <include>my.group:my-mvn-a:jar:sources:${project.version}</include>
            </includes>
        </dependencySet>
    </dependencySets>
</assembly>

,但是zip中仅包含具有已编译类的jar.为什么不包括使用maven-sources-plugin构建的source jar?

but only the jar with the compiled classes is included in the zip. Why does it not include the sources jar build using the maven-sources-plugin?

推荐答案

在我看来,生成源的阶段为时已晚. verify阶段紧随package阶段之后,这意味着您的源jar正在生成,但是要好在打包程序集之后.将maven-sources-plugin的阶段设置为package并确保maven-assembly-plugin在同一阶段中定义但在其后声明(因为Maven以连续的顺序调用插件).

It seems to me that the phase in which you're generating the sources is too late. The verify phase comes after the package phase which means that your sources jar is getting generated, but it's well after the packaging of the assembly has occurred. Set the phase of the maven-sources-plugin to package and make sure the maven-assembly-plugin is defined in the same phase but declared after it (as Maven invokes the plugins in consecutive order).

我知道了.您尚未定义对源工件的依赖关系.添加以下内容,它将起作用:

I figured it out. You haven't defined a dependency to the sources artifact. Add the following and it will work:

<dependency>
    <groupId>my.group</groupId>
    <artifactId>my-mvn-a</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <classifier>sources</classifier>
</dependency>

这篇关于没有附带Maven-assembly-plugin的源jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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