解决:You have to use a classifier to attach supplemental artifacts to the project instead of replacing them,jenkins发版[WARNING] JAR will be empty - no content was marked for inclusion!

背景

因为最近是新项目的开发,所以环境特别的不稳定,经常出各种错误,这次记录一下,帮助一下可能帮助到的伙计们

起因

在21年4月22号的时候,我突然发现我发版发不了了,发版报错:[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:3.1.2:jar (default-jar) on project biz-payment: You have to use a classifier to attach supplemental artifacts to the project instead of replacing them. -> [Help 1]
经过我向上排查,定位到了报错的模块名。

再往上定位发现有一个警告提示:[WARNING] JAR will be empty - no content was marked for inclusion!
在这里插入图片描述

排查过程

  1. 首先想到的就是百度,先百度了报错提示的【You have to use a classifier to attach supplemental artifacts to the project instead of replacing them】,都是让在打包插件那里加配置,参数,比方加package
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
      <id>service-jar</id>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
      </goals>
      <configuration>
        <classifier>bak</classifier> <!-- 生成deploy-0.0.1-SNAPSHOT-bak.jar -->
        <classesDirectory>${project.build.directory}/webservice/</classesDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

或者设置bak,发现都没有用

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <version>3.0.2</version>
  <executions>
    <execution>
      <id>service-jar</id>
      <phase>package</phase>
      <goals>
        <goal>jar</goal>
      </goals>
      <configuration>
        <classifier>bak</classifier> <!-- 生成deploy-0.0.1-SNAPSHOT-bak.jar -->
        <classesDirectory>${project.build.directory}/webservice/</classesDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
  1. 百度warning的 JAR will be empty - no content was marked for inclusion。都是说是因为模块里面没有内容,导致报错的,后面我尝试在提示报错的模块加了一个test.java的内容。果然可以正常编译,到下一个空模块才报错,但是因为模块比较多,我不可能每个都去加,比较费时间,加上之前是没有问题的。就是22号之后才有问题的,上次成功发版是在20号。
  2. 我打算对比一下20-22号的代码,看看是否有改动pom文件之类的,导致发版不成功,对比中,以当时的想法是并没有发现有调整打包相关插件
  3. 最后只能用最笨的办法,对比上一次成功的发版,和本次失败的jenkins发版日志有什么不同,最后真让我发现了问题,成功和失败的发版,maven插件的版本号不同
    失败:
    失败
    成功:
    成功
    这下就有了明确的目标。
  4. 这时候再去看pom文件的依赖,发现之前同事为了解决一个问题,引入了
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/>
    </parent>

点进去看了一下版本号发现和失败的maven插件一直,所以至此定位到是版本的问题。
在这里插入图片描述

解决问题

1、第一种方法就是将每一个模块都填充一个test.java。就是比较耗费时间
2、第二种方法,既然是版本的问题,那我们就替换版本号就完了,但是发现引入的是parent的标签,并不能通过标签去排除再重新引入。谷歌,百度查了一些资料。最后是将注释掉

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/>
    </parent>

加入:

<dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <version>1.5.4.RELEASE</version>
      </dependency>
      <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-dependencies</artifactId>
        <version>2.2.5.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

至此问题解决。
有问题欢迎伙计们留言讨论,不对的地方也欢迎伙计们指出。

转载请注明出处

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐