Recently, I was working on upgrading the dependencies of one of my team's projects. After changes, project built successfully locally on my laptop. But the same code change threw compilation error on Jenkins.
The errors I am encountering is related to class file for xxx.xxx.xxx. not found in powermockito package. Attaching some relevant pieces of code for reference.
Pervious pom version used:
... some lines above it ...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--dropwizard versions-->
<dropwizard.version>1.3.5</dropwizard.version>
<dropwizard.swagger.version>1.0.0-2-auth-SNAPSHOT</dropwizard.swagger.version>
<dropwizard.bundle.version>1.3.5-1</dropwizard.bundle.version>
<dropwizard.requestinfo>1.3.5-3</dropwizard.requestinfo>
<dropwizard.rosey.data.provider.version>1.3.5-3</dropwizard.rosey.data.provider.version>
<dropwizard.service.discovery>1.3.5-0</dropwizard.service.discovery>
<dropwizard.rmq.actor.version>1.2.2-1</dropwizard.rmq.actor.version>
<dropwizard.riemann.version>1.3.5-4</dropwizard.riemann.version>
<!--hystrix versions-->
<hystrix.dropwizard.version>0.4</hystrix.dropwizard.version>
<hystrix.configurator.version>0.0.6</hystrix.configurator.version>
<hystrix.version>1.5.3</hystrix.version>
<hystrix.wrapper.version>1.0-SNAPSHOT</hystrix.wrapper.version>
<!--internal clients-->
<user-service-model.version>1.7.91</user-service-model.version>
<kratos.version>0.8.2-SNAPSHOT</kratos.version>
<rosey.dropwizard.config>1.14</rosey.dropwizard.config>
<!--others-->
<mysql.driver.version>5.1.38</mysql.driver.version>
<okhttp3.version>3.4.1</okhttp3.version>
<lombok.version>1.18.8</lombok.version>
<junit.version>4.12</junit.version>
<powemock.version>1.7.3</powemock.version>
<h2.version>1.4.191</h2.version>
<square.okhttp.version>3.4.1</square.okhttp.version>
<rmq.version>4.1.0</rmq.version>
<zookeeper.version>3.4.13</zookeeper.version>
<curator.version>4.0.1</curator.version>
</properties>
... some lines below it ...
Current pom version used:
... some lines above it ...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--dropwizard versions-->
<dropwizard.version>1.3.12</dropwizard.version>
<dropwizard.swagger.version>1.3.7-1</dropwizard.swagger.version>
<dropwizard.bundle.version>1.3.5-1</dropwizard.bundle.version>
<dropwizard.requestinfo>1.3.5-8</dropwizard.requestinfo>
<dropwizard.rosey.data.provider.version>1.3.5-6</dropwizard.rosey.data.provider.version>
<dropwizard.service.discovery>1.3.12-3</dropwizard.service.discovery>
<dropwizard.rmq.actor.version>1.3.12-1</dropwizard.rmq.actor.version>
<dropwizard.db.sharding.bundle.version>1.3.12-3</dropwizard.db.sharding.bundle.version>
<dropwizard.riemann.version>1.3.12-1</dropwizard.riemann.version>
<!--hystrix versions-->
<hystrix.dropwizard.version>0.4</hystrix.dropwizard.version>
<hystrix.configurator.version>0.0.6</hystrix.configurator.version>
<hystrix.version>1.5.3</hystrix.version>
<!--internal clients-->
<user-service-model.version>1.7.96-STAGE-SNAPSHOT</user-service-model.version>
<kratos.version>0.9.6</kratos.version>
<rosey.dropwizard.config>1.15</rosey.dropwizard.config>
<!-- storage -->
<aerospike.version>3.3.0</aerospike.version>
<mock.aerospike.version>0.0.4</mock.aerospike.version>
<!--others-->
<okhttp3.version>3.4.1</okhttp3.version>
<lombok.version>1.18.8</lombok.version>
<junit.version>4.12</junit.version>
<powemock.version>1.7.3</powemock.version>
<guava.version>28.0-jre</guava.version>
<h2.version>1.4.199</h2.version>
<rmq.version>5.7.2</rmq.version>
<zookeeper.version>3.4.13</zookeeper.version>
<curator.version>4.2.0</curator.version>
<sentinel.model.version>1.0-SNAPSHOT</sentinel.model.version>
</properties>
... some lines below it ...
Shortend error logs:
... some code above it ...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/MerchantResourceTest.java:[19,1] cannot access org.powermock.api.support.membermodification.MemberModifier
class file for org.powermock.api.support.membermodification.MemberModifier not found
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/VPAResourceTest.java:[29,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/VPAResourceTest.java:[30,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/services/PrimerServiceTest.java:[28,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/services/PrimerServiceTest.java:[29,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/AddressResourceTest.java:[22,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/AddressResourceTest.java:[23,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/services/WalletServiceTest.java:[27,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/services/WalletServiceTest.java:[28,1] static import only from classes and interfaces
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/MerchantResourceTest.java:[24,25] cannot access org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner
class file for org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner not found
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/VPAResourceTest.java:[37,25] incompatible types: java.lang.Class<org.powermock.modules.junit4.PowerMockRunner> cannot be converted to java.lang.Class<? extends org.junit.runner.Runner>
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/BaseResourceTest.java:[26,19] package org.mockito does not exist
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/BaseResourceTest.java:[30,26] package org.mockito does not exist
[ERROR] /var/lib/jenkins/jobs/UserService_Develop/workspace/src/test/java/com/xxxxxxx/userservice/resources/BaseResourceTest.java:[30,1] static import only from classes and interfaces
... some code below it ...
Experiment I did: When I removed the test scope from the powermockito dependency, everything worked like a charm.
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>${powemock.version}</version>
<scope>test</scope> <- This line
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>${powemock.version}</version>
<scope>test</scope> <- This line
</dependency>
Pasting mockito's maven dependency tree below
... some line above it ...
[INFO] +- org.powermock:powermock-api-mockito:jar:1.7.3:test
[INFO] | +- org.powermock:powermock-api-mockito-common:jar:1.7.3:test
[INFO] | | \- org.powermock:powermock-api-support:jar:1.7.3:test
[INFO] | \- org.mockito:mockito-core:jar:1.10.19:test
[INFO] +- org.powermock:powermock-module-junit4:jar:1.7.3:test
[INFO] | +- org.powermock:powermock-module-junit4-common:jar:1.7.3:test
[INFO] | | +- org.powermock:powermock-reflect:jar:1.7.3:test
[INFO] | | \- org.powermock:powermock-core:jar:1.7.3:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
... some lines below it ...
Maven command which is executing on Jenkins, below sample is taken from console log:
Executing Maven: -B -f /var/lib/jenkins/jobs/UserService_Develop/workspace/pom.xml -U clean package cobertura:cobertura docker:build docker:push -Pdocker -Dproject.version=1.8.23-SNAPSHOT -Dbuild.number=1501 -Dbuild.revision=9d8d00591c23b061b07e1a08c00ff024db8ba318 -Dmaven.test.failure.ignore=true -DskipTests -DargLine=-Xmx512m
Ideally, it should not have happened. I googled for few days found this blog Why your tests may pass locally but fail in Jenkins. Unfortunately, nothing seems to work for me. Need some assitance here. Thanks!
Your experiment shows that the dependency tree is not the problem. What is the problem is the scope of the dependency. The test scope only adds the dependency to the classpath for test compilation and test execution.
What may go wrong here is that your test classes are actually compiled in the compile phase, not the test-compile phase. A test you can do to check this is to leave the scope as test and try to build the project with mvn compile, which should NOT build the test sources if everything is configured correctly.
Other than that, is it hard to guess what exactly your are doing and where it could go wrong without seeing the complete pom.xml, but I hope this gives you a starting point.
Here is an hypothesis on why code compiled when you removed the test scope:
In terms of scope, Maven documentation suggests the following:
compile
This is the default scope, used if none is specified. Compile
dependencies are available in all classpaths of a project.
Furthermore, those dependencies are propagated to dependent projects.
test
This scope indicates that the dependency is not required for normal
use of the application, and is only available for the test compilation
and execution phases. This scope is not transitive.
Now, this may mean that the classpath for scope test compilation may potentially differ from the classpath for scope compile
When you removed the test scope, the mockito jars were found as the default scope is compile
Related
I have a Maven project using Jetty as a runner – in case it's relevant. My pom.xml file contains the following
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>7.17.3</version>
</dependency>
It used to be 7.14.2 and I upgraded it. After cleaning and refreshing, IntelliJ says some of the classes in one of the packages on which transport depends can't be found anymore. I tried forcing refreshes, cleaned the project multiple times, resolving dependencies... nothing, the project doesn't even build anymore because of those missing classes. I figured I'd downgrade it again, just in case I missed a breaking change somewhere but now I have the older version and the classes are still not there. I switched to a branch which I'm sure works and sure enough everything builds and runs just fine.
I checked with mvn dependency:tree and this is what comes up:
[INFO] +- org.elasticsearch.client:transport:jar:7.17.3:compile
[INFO] | +- org.elasticsearch:elasticsearch:jar:7.17.3:compile
[INFO] | | +- org.elasticsearch:elasticsearch-core:jar:7.17.3:compile
[INFO] | | +- org.elasticsearch:elasticsearch-secure-sm:jar:7.17.3:compile
[INFO] | | +- org.elasticsearch:elasticsearch-x-content:jar:7.17.3:compile
elasticsearch-x-content is the package that is supposed to contain those classes and it shows up correctly (in the downgraded version too) but the classes are nowhere to be found.
I have had similar problems in the past where either Maven or IntelliJ IDEA randomly decide to stop seeing things that they were both happy to see just 20 minutes prior, and I never know how I manage to "fix" the issue each time so I don't have a repeatable series of incantations that I can offer as a clue.
Any ideas?
EDIT: I just tried a mvn dependency:purge-local-repository and no joy. I tried refreshing Maven from inside IntelliJ IDEA, nothing. I tried mvn compile and mvn package -U and nope.
EDIT 2: This is the error I'm getting on mvn compile:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[20,40] error: cannot find symbol
[ERROR] package org.elasticsearch.common.xcontent
/Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[21,40] error: cannot find symbol
[ERROR] package org.elasticsearch.common.xcontent
/Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[22,40] error: cannot find symbol
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.623 s
[INFO] Finished at: 2022-04-26T13:56:15+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project isaac-api: Compilation failure: Compilation failure:
[ERROR] /Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[20,40] error: cannot find symbol
[ERROR] package org.elasticsearch.common.xcontent
[ERROR] /Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[21,40] error: cannot find symbol
[ERROR] package org.elasticsearch.common.xcontent
[ERROR] /Users/morpheu5/src/isaac/isaac-api/src/main/java/uk/ac/cam/cl/dtg/segue/etl/ElasticSearchIndexer.java:[22,40] error: cannot find symbol
Did you try running mvn compile from the command line and then refresing the project? Sometimes Intellij will bug out and not actually download a dependency even though it says it's trying to (happened to me a week ago).
My pom.xml is messy, having collected cruft over time. Is there any automated way to "clean up" a pom? Like a linter but for maven.
In IntelliJ I can run Analyze > Inspect Code and get a list of unused functions, silly iterators, and probable bugs. I think I'm looking for the same thing for my pom
Unused repositories, pluginRepositories
Unused properties
properties that collide with settings specified within the plugin
Dependencies with more recent versions (mvn versions:display-dependency-updates works, but doesn't restrict to non-breaking version updates)
For a simple static analysis of your pom.xml, you can use the lint-maven-plugin.
Add the following to your pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.lewisd</groupId>
<artifactId>lint-maven-plugin</artifactId>
<version>0.0.11</version>
</plugin>
</plugins>
</build>
Run the lint:check goal to check your pom.xml for violations.
$ mvn lint:check
The plugin will report any violations in your pom.xml as demonstrated below.
[INFO] --- lint-maven-plugin:0.0.11:check (default-cli) # maven-sample ---
[INFO] Writing summary report
[INFO] [LINT] Completed with 3 violations
[INFO] [LINT] OSSDevelopersSectionRule: missing <developers/> section : 0:0 : /Users/jdoe/workspace/maven-sample/pom.xml
[INFO] [LINT] OSSInceptionYearRule: missing <inceptionYear/> information : 0:0 : /Users/jdoe/workspace/maven-sample/pom.xml
[INFO] [LINT] GAVOrder: Found 'name' but was expecting 'packaging' : 19:8 : /Users/jdoe/workspace/maven-sample/pom.xml
You can see a list of available rules by running the lint:list goal.
Sounds like there isn't a pom.xml linter like jshint.com that I can paste my pom into and get advice out.
I'm evaluating the jgitver Maven extension for calculating artefact versions from git metadata.
jgitver provides the commit datetime in a property called jgitver.head_commit_datetime, but I can't figure out how to include the timestamp in the version string.
Can anyone help?
#otto.poellath, you can use the configuration property useGitCommitTimestamp and set it to true ; it is only available in the non maven mode of jgitver as it is a bit clashing with strict maven SNAPSHOTs.
So if you have your .mvn/jgitver.config.xml config file that contains something like the following it will work:
<mavenLike>false</mavenLike>
<useGitCommitTimestamp>true</useGitCommitTimestamp>
Here is an output of a local mvn validate on jgitver-maven-plugin itself using such a configuration
H:\jgitver-maven-plugin>mvn validate
[INFO] using jgitver configuration file: H:\jgitver-maven-plugin\.mvn\jgitver.config.xml
[INFO] Scanning for projects...
[INFO] Using jgitver-maven-plugin [1.3.0] (sha1: ef8eec9f820d662e63a84f1210c377183e450cbd)
[INFO] jgitver-maven-plugin is about to change project(s) version(s)
[INFO] fr.brouillard.oss::jgitver-maven-plugin::0 -> 1.3.1-20180710075533-integration
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jgitver Maven Plugin 1.3.1-20180710075533-integration
[INFO] ------------------------------------------------------------------------
...
Thanks to maven lazy evaluation, you can provide them into the build using the versions plugin, something like:
mvn jgitver versions:set -DnewVersion=1.0.\${jgitver.head_commit_datetime} versions.commit
Try that and let me know.
It basically pass the property onto the versions:set plugin, and this will rewrite all pom files to the given new version.
I am a little confused about the option "includeParents" of the dependency:list goal of the Maven dependency plugin
http://maven.apache.org/plugins/maven-dependency-plugin/list-mojo.html
It seems to me that the parent of the pom itself are not included into the list (I mean the parent of the project pom to which we apply the goal). Is this really the case or did I make some mistake? If so, is there a way to get the parent pom of the project as well?
EXAMPLE:
I used the pom of org.sonatype.plugins:sisu-maven-plugin:1.4 from MavenCentral. It contains a reference to the parent
<parent>
<groupId>org.sonatype.plugins</groupId>
<artifactId>plugins-parent</artifactId>
<version>9</version>
</parent>
But the result of mvn dependency:list -DincludeParents=true is:
javax.inject:javax.inject:jar:1:compile
org.apache.maven:maven-artifact-manager:jar:2.0.8:compile
javax.annotation:jsr250-api:jar:1.0:compile
com.google.code.findbugs:jsr305:jar:1.3.9:compile
org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.2.0:compile
org.apache.maven:maven-model:jar:2.0.8:compile
org.apache.maven:maven-plugin-registry:jar:2.0.8:compile
org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.6:compile
org.apache.maven:maven-project:jar:2.0.8:compile
org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-44:compile
org.apache.maven:maven-settings:jar:2.0.8:compile
aspectj:aspectjrt:jar:1.5.3:compile
junit:junit:jar:4.8.2:test
org.apache.maven:maven-repository-metadata:jar:2.0.8:compile
org.sonatype.sisu:sisu-inject-bean:jar:2.5.3:compile
com.google.guava:guava:jar:11.0.2:compile
org.apache.maven.shared:maven-common-artifact-filters:jar:1.4:compile
org.apache.maven.wagon:wagon-provider-api:jar:1.0-beta-2:compile
org.apache.maven:maven-artifact:jar:2.0.8:compile
org.codehaus.plexus:plexus-utils:jar:3.0.15:compile
javax.enterprise:cdi-api:jar:1.0:compile
org.apache.maven:maven-plugin-api:jar:2.0:compile
org.apache.maven:maven-profile:jar:2.0.8:compile
org.codehaus.plexus:plexus-classworlds:jar:1.2-alpha-10:compile
The parameter includeParents was introduced in version 2.8 of the Maven Dependency Plugin:
Include parent poms in the dependency resolution list.
[...]
Since: 2.8
However, the specific Maven project on which you're launching this command declares version 2.2 of the plugin. Here's how I tracked this: sisu-maven-plugin-1.4 has as parent org.sonatype.plugins:plugins-parent:9, which itself has as parent org.sonatype.forge:forge-parent:12, which finally declares version 2.2 of the plugin... Maven will prefer to use that version since it is directly declared in the POM of the project.
Note that you can spot this in the logs as well. When running the command on this project, the logs are:
[INFO] Building Sisu Maven Plugin 1.4
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.2:list (default-cli) # sisu-maven-plugin ---
[INFO]
showing that version 2.2 is the one used.
As such, you just need to force the usage of a version greater than 2.8 for the includeParents parameter to take effect, for example using 2.10 which is the current latest:
mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:list -DincludeParents
I have to work with an EMF-Project and need to use some of the classes in another package.
When I try to build the generated code with maven I get this Failure:
[INFO] 6 errors
[INFO] -------------------------------------------------------------
[INFO]------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO]------------------------------------------------------------------------
[INFO] Total time: 2.844 s
[INFO] Finished at: 2015-03-31T16:25:42+02:00
[INFO] Final Memory: 14M/163M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project datamodel: Compilation failure:
Compilation failure:
[ERROR] /C:/.../util/ModelSwitch.java:[20,34] cannot find symbol
[ERROR] symbol: class Switch
[ERROR] location: package org.eclipse.emf.ecore.util
[ERROR] /C:/.../util/ModelSwitch.java:[85,38] cannot find symbol
[ERROR] symbol: class Switch
[ERROR] /C:/.../util/ModelSwitch.java:[114,9] method does not override or implement a method from a supertype
[ERROR] /C:/.../util/ModelSwitch.java:[126,9] method does not override or implement a method from a supertype
[ERROR] /C:/.../util/ModelSwitch.java:[1341,9] method does not override or implement a method from a supertype
[ERROR] /C:/.../util/ModelAdapterFactory.java:[365,35] method doSwitch in class com...util.ModelSwitch<T1> cannot be applied to given types;
[ERROR] required: int,org.eclipse.emf.ecore.EObject
[ERROR] found: org.eclipse.emf.ecore.EObject
[ERROR] reason: actual and formal argument lists differ in length
All libraries are imported and in the pom, yet it still got problems with the generated ModelSwitch class.
This Error and the fact, that Eclipse Luna is buggy as hell are driving me crazy! Could somebody please help me and explain how to fix this?
Take a look at the different version in the repository. It seems like EMF renamed their artifacts some time ago. Instead of this (analogously for your other EMF dependencies):
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>ecore</artifactId>
<version>2.6.1.v20100914-1218</version>
</dependency>
try to use this form (note the different artifactId):
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.11.0-v20150123-0347</version>
</dependency>
Here, much newer versions are available. For me, every version from 2.8 upwards seems to work. You could also use a range, to always get the latest version:
<version>[2.8.0,2.99.99]</version>
These are the latest versions of the components you have as far as I can tell
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>ecore</artifactId>
<version>2.3.0-v200706262000</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>common</artifactId>
<version>2.3.0-v200706262000</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.11.0-v20150123-0347</version>
</dependency>