Skip to content
Advertisement

Maven build fails ONLY when run with jenkins

I have a Java project that is committed to GitHub. The project consists of 3 modules. I have configured the Jenkins Workflow Multibranch Pipeline plugin to build the 3 modules.

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. 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.

These are the maven plugins that I use in all 3 of the modules:

    <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. 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.

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.

Advertisement

Answer

Try removing .m2 folder from your jenkins server. That way jenkins will trigger downloading of all your dependencies and you well get new version. Actually problem you have encountered is quite common.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement