gpt4 book ai didi

java - Maven 构建仅在使用 jenkins 运行时失败

转载 作者:行者123 更新时间:2023-11-30 02:57:56 26 4
gpt4 key购买 nike

我有一个致力于 GitHub 的 Java 项目。该项目由 3 个模块组成。我已经配置了 Jenkins Workflow Multibranch Pipeline 插件来构建 3 个模块。

node {
// Mark the code checkout 'stage'....
// stage 'Checkout'

// Get some code from a GitHub repository
git url: 'git@github.com:me/myproject.git', credentialsId: '###'

// Get the maven tool.
// ** NOTE: This 'M3' maven tool must be configured
// ** in the global configuration.
def mvnHome = tool 'M3'

stage 'Build module 1'
sh "${mvnHome}/bin/mvn -f module-1/ clean install"

stage 'Build module 2'
sh "${mvnHome}/bin/mvn -f module-2/ clean install"

stage 'Build module 3'
sh "${mvnHome}/bin/mvn -f module-3/ clean install"
}

Maven 构建前 2 个模块没有任何问题。但在第三个模块上我收到以下错误:

 Compilation failure
/var/lib/jenkins/workspace/.../MyClass.java:[136,44] cannot find symbol
symbol: method setStore(java.util.UUID,java.util.UUID,java.util.Date,int)
location: variable _storeService of type com.my.module3.interfaces.StoreService

我有红色,可能是maven-compiler-plugin的版本有问题,所以我将其更新到最新的3.5.1版本,但确实如此没有帮助。

这些是我在所有 3 个模块中使用的 Maven 插件:

    <plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>module3-${project.version}</finalName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.my.module3.App</Main-Class>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

当我在 IntelliJ 中构建模块时,没有错误。我什至将存储库拉到一个新文件夹中,并对 module3 使用 mvn clean install 命令,并且顺利完成。

我不知道问题出在哪里。我的代码似乎没有问题,因为它工作正常(我已经调试过它)。任何帮助或建议将不胜感激。

最佳答案

尝试从 jenkins 服务器中删除 .m2 文件夹。这样 Jenkins 将触发下载所有依赖项,并且您将获得新版本。其实你遇到的问题是很常见的。

关于java - Maven 构建仅在使用 jenkins 运行时失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36745553/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com