简体   繁体   English

仅当与jenkins一起运行时,Maven构建才会失败

[英]Maven build fails ONLY when run with jenkins

I have a Java project that is committed to GitHub. 我有一个致力于GitHub的Java项目。 The project consists of 3 modules. 该项目包括3个模块。 I have configured the Jenkins Workflow Multibranch Pipeline plugin to build the 3 modules. 我已经配置了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 builds the first 2 modules with no problem. Maven可以毫无问题地构建前两个模块。 But on the third module I get the following error: 但是在第三个模块上,出现以下错误:

 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

I have red that there may be a problem with the version of maven-compiler-plugin so I updated it to the latest 3.5.1 version, but it did not help. 我已经冒昧地说过maven-compiler-plugin的版本可能有问题,所以我将其更新为最新的3.5.1版本,但没有帮助。

These are the maven plugins that I use in all 3 of the modules: 这些是我在所有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>

When I build the module in IntelliJ there are no errors. 当我在IntelliJ中构建模块时,没有错误。 I even pulled the repository in a new folder and used the mvn clean install command for the module3 and it finishes without a problem. 我什至将存储库拉到一个新文件夹中,并对模块3使用了mvn clean install命令,它可以顺利完成。

I have no idea where the problem is. 我不知道问题出在哪里。 It does not seem that there is something wrong with my code, as it works correctly (I have debugged it). 我的代码似乎没有问题,因为它可以正常工作(我已经调试了它)。 Any help or suggestions would be greatly appreciated. 任何帮助或建议,将不胜感激。

Try removing .m2 folder from your jenkins server. 尝试从jenkins服务器中删除.m2文件夹。 That way jenkins will trigger downloading of all your dependencies and you well get new version. 这样,jenkins将触发所有依赖项的下载,并且您将获得新版本。 Actually problem you have encountered is quite common. 实际上,您遇到的问题很常见。

You can choose the option "Delete Workspace before build starts" in Build Environment configuration. 您可以在构建环境配置中选择选项“在构建开始之前删除工作区”。

This option is accessible after install "Workspace Cleanup Plugin" 安装“工作区清理插件”后可以访问此选项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM