Maven 构建仅在使用 jenkins 运行 时失败
Maven build fails ONLY when run with jenkins
我有一个 Java 项目致力于 GitHub。该项目由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 将触发所有依赖项的下载,您将获得新版本。其实你遇到的问题很常见。
您可以在构建环境配置中选择选项"Delete Workspace before build starts"。
安装后可以访问此选项"Workspace Cleanup Plugin"
我将 jenkins 文件夹移动到另一个驱动器后遇到了这个问题。令人困惑的是,从远程服务器中的 cmd 手动 运行ning maven 工作正常,但当从管道 运行ning 时失败。删除 .m2 没有帮助。原因是在移动之前我做了 jenkins.exe uninstall
然后 jenkins.exe install
更新 windows service / jenkins home 变量(我发现这是某处的推荐)。新服务已配置为使用系统用户,因此令人困惑地使用了位于 C:/Windows 目录内某处的 .m2。转到服务,并在属性对话框中更改用户服务 运行 已解决。 OP 有点离题,但我认为这可能对其他人有用,因为这个问题是我在搜索我的问题时发现的第一个有希望的事情
我有一个 Java 项目致力于 GitHub。该项目由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 将触发所有依赖项的下载,您将获得新版本。其实你遇到的问题很常见。
您可以在构建环境配置中选择选项"Delete Workspace before build starts"。
安装后可以访问此选项"Workspace Cleanup Plugin"
我将 jenkins 文件夹移动到另一个驱动器后遇到了这个问题。令人困惑的是,从远程服务器中的 cmd 手动 运行ning maven 工作正常,但当从管道 运行ning 时失败。删除 .m2 没有帮助。原因是在移动之前我做了 jenkins.exe uninstall
然后 jenkins.exe install
更新 windows service / jenkins home 变量(我发现这是某处的推荐)。新服务已配置为使用系统用户,因此令人困惑地使用了位于 C:/Windows 目录内某处的 .m2。转到服务,并在属性对话框中更改用户服务 运行 已解决。 OP 有点离题,但我认为这可能对其他人有用,因为这个问题是我在搜索我的问题时发现的第一个有希望的事情