如何将自定义构建的jar文件注册为Maven主工件? [英] How to register a custom built jar file as maven main artifact?

查看:195
本文介绍了如何将自定义构建的jar文件注册为Maven主工件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目希望传递一个jar文件:

I have a project expected to deliver a jar file:

<packaging>jar</packaging>

但是jar以自定义方式构建,因此使用jar:jar完成的默认包装已被禁用

but the jar is built in a custom way, so the default packaging done with jar:jar has been disabled

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
  <version>2.3.2</version>
  <executions>
    <execution>
      <id>default-jar</id>
      <phase>none</phase>
    </execution>
  </executions>
</plugin>

但是当我想在现有罐子上应用shade:shade时,我会得到一个错误

but then when I want to apply shade:shade on the existing jar I get an error

项目主工件不存在.

The project main artifact does not exist.

我认为maven不了解我的自定义工具创建的.jar文件.怎么知道的,因为 antrun attachArtifact 不会不行

I assume that maven doesn't know about the .jar file created by my custom tool. How to let it know, because antrun attachArtifact doesn't work

<attachartifact file="./bin/classes.jar" classifier="" type="jar"/>

我得到的错误是

发生了Ant BuildException:org.apache.maven.artifact.InvalidArtifactRTException:对于工件{:jar}:附加工件必须具有与其对应的主工件不同的ID.

An Ant BuildException has occured: org.apache.maven.artifact.InvalidArtifactRTException: For artifact {:jar}: An attached artifact must have a different ID than its corresponding main artifact.

所以这不是注册主要工件的方法...是否有(不编写自定义Java插件)?

So this is not the method to register main artifact... Is there any (without writing custom java plugin)?

谢谢, 卢卡斯

推荐答案

我检查了JarMojo的来源,它给了我一个想法,如何使用Groovy(通过gmaven)解决它

I checked the sources of JarMojo and it gave me an idea how to solve it with Groovy (via gmaven)

<plugin>
  <groupId>org.codehaus.gmaven</groupId>
  <artifactId>gmaven-plugin</artifactId>
  <version>1.3</version>
  <executions>
    <execution>
      <id>set-main-artifact</id>
      <phase>package</phase>
      <goals> 
        <goal>execute</goal>
      </goals>
      <configuration>
        <source>
          project.artifact.setFile(new File("./bin/classes.jar"))
        </source>
      </configuration>
    </execution>
  </executions>
</plugin>

它有效!:)

这篇关于如何将自定义构建的jar文件注册为Maven主工件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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