附加主要工件(如果由maven-assembly-plugin构建)

时间:2018-09-05 04:44:44

标签: java maven jar

我在构建Maven项目时遇到问题。它需要构建两个jars-其中一个默认情况下是 maven-jar-plugin 构建的,其中只包含我的Java代码的已编译类文件夹,另一个是 maven-assembly定制的一个打包阶段中的-plugin 是一个可执行jar,其中添加了所有依赖项jar。

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-assembly- 
plugin:2.2-beta-5:single (executable-jar-generation) on project enhanced- 
search: Execution executable-jar-generation of goal 
org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5:single failed: For 
artifact {com.fmr.es:enhanced-search:1.0:jar}: An attached artifact must 
have a different ID than its corresponding main artifact. -> [Help 1]

由于问题或多或少相同,我一直以Manually attach main artifact if built by maven-assembly-plugin作为参考。

正如答案所说,我添加了ant-plugin代码,该代码用可执行文件覆盖了我的主jar,并以 package阶段安装在存储库中。

但是在maven甚至没有到达此插件之前,就会出现上述错误。反之亦然,因为必须首先创建一个可执行jar才能覆盖主要对象。

真的很感谢任何反馈。

以下是程序集插件,该程序集将创建我的可执行jar以及assembly.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <executions>
        <execution>
            <phase>package</phase>
            <id>executable-jar-generation</id>
            <goals>
                <goal>single</goal>
            </goals>
            <configuration>
                <finalName>executable-enhanced-search-1.0</finalName>
                <descriptors>
                    <descriptor>assembly-jar.xml</descriptor>
                </descriptors>
            </configuration>
        </execution>
    </executions>
</plugin>

<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">
    <baseDirectory>/</baseDirectory>
    <formats>
        <format>jar</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>../../target/classes</directory>
            <includes>
                <include>**/*</include>
            </includes>
           <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>false</unpack>
        </dependencySet>
    </dependencySets>
</assembly>

以下是我上面发布的链接中提到的量身定制的ant任务。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.6</version>
    <executions>
        <execution>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <copy file="../../target/executable-enhanced-search- 
                         1.0.jar" tofile="../../target/enhanced-search- 
                         1.0.jar" overwrite="true" />
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

0 个答案:

没有答案