【发布时间】:2016-08-13 05:38:48
【问题描述】:
我有一个提交给 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 命令,它完成没有问题。
我不知道问题出在哪里。我的代码似乎没有问题,因为它可以正常工作(我已经调试过了)。任何帮助或建议将不胜感激。
【问题讨论】:
-
看来storeservice不是最新版本。因为 Jenkins 在构建之前需要检查源代码。您应该检查:模块 3 的最新源代码已提交给 Git?如果是,您可以转到 Jenkins 构建文件夹并检查它是否获得了模块 3 源代码的最新版本。在 Intelli 上构建时,源代码是最新的。所以构建成功
-
代码为最新版本。我什至删除了
git行,从我的 dev 文件夹中复制了代码并将其粘贴到 Jenkins 工作区文件夹中。我还检查了文件。代码在那里。 -
尝试从您的 jenkins 服务器中删除 .m2 文件夹。这样 jenkins 将触发下载所有依赖项,并且您将获得新版本。其实你遇到的问题很常见。
-
@BrankoIlic 谢谢。这解决了问题。你能写一个答案,以便我标记它吗?
标签: java maven jenkins maven-3