Obtaining a Maven-Instance from Plexus - java

I'm currently attempting to get PlexusContainer to give me an initialized Maven-instance outside of a maven or eclipse execution context.
For that purpose I have following code (simplified):
PlexusContainer container = null;
try {
container = new DefaultPlexusContainer();
container.lookup(MavenResolutionTask.class).run();
container.dispose();
} catch (Exception e) {
e.printStackTrace();
}
// --- MavenResolutionTask.java:
#Component(role = MavenResolutionTask.class)
// ResolutionTask is an abstract class
// implementing Runnable and extending CompletableFuture
public class MavenResolutionTask extends ResolutionTask {
#Requirement
private Maven maven;
}
Given that I had the standard plexus-component-metadata:process-classes plugin execution in my pom.xml I would've liked if this had worked like this.
Unfortunately running this code results in a LookupException with the following reason (stacktrace omitted for brevity):
WARN Sisu - Error injecting: org.apache.maven.project.DefaultProjectBuildingHelper
com.google.inject.ProvisionException: Guice provision errors:
1) No implementation for org.apache.maven.repository.RepositorySystem was bound.
while locating org.apache.maven.project.DefaultProjectBuildingHelper
WARN Sisu - Error injecting: org.apache.maven.project.DefaultProjectBuilder
com.google.inject.ProvisionException: Guice provision errors:
1) No implementation for org.apache.maven.repository.RepositorySystem was bound.
while locating org.apache.maven.project.DefaultProjectBuildingHelper
at ClassRealm[plexus.core, parent: null]
at ClassRealm[plexus.core, parent: null]
while locating org.apache.maven.project.ProjectBuildingHelper
while locating org.apache.maven.project.DefaultProjectBuilder
...
To remediate the missing bindings and prevent myself from having to go through the trouble of manually registering the complete dependency-graph of maven I attempted to merge the component descriptors included in my dependencies with the one generated for my application.
For that purpose I copied all dependencies into target/dependency and ran some shell-scripts to get a list of all dependencies that include a components.xml.
I pass these dependencies to an execution of dependency:unpack before then passing the extracted locations to the metadata-merger like so:
<plugin>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-component-metadata</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>process-classes</id>
<goals>
<goal>generate-metadata</goal>
</goals>
</execution>
<execution>
<id>process-test-classes</id>
<goals>
<goal>generate-test-metadata</goal>
</goals>
</execution>
<execution>
<id>merge-descriptors</id>
<phase>process-classes</phase>
<goals>
<goal>merge-metadata</goal>
</goals>
</execution>
</executions>
<configuration>
<output>${plexus.outputFile}</output>
<descriptors>
<descriptor>${plexus.outputFile}</descriptor>
<!--./aether-transport-wagon-1.1.0.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/aether-transport-wagon/META-INF/plexus/components.xml</descriptor>
<!--./maven-aether-provider-3.1.0.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-aether-provider/META-INF/plexus/components.xml</descriptor>
<!--./maven-artifact-manager-2.2.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-artifact-manager/META-INF/plexus/components.xml</descriptor>
<!--./maven-core-3.1.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-core/META-INF/plexus/components.xml</descriptor>
<!--./maven-model-builder-3.1.0.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-model-builder/META-INF/plexus/components.xml</descriptor>
<!--./maven-plugin-registry-2.2.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-plugin-registry/META-INF/plexus/components.xml</descriptor>
<!--./maven-profile-2.2.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-profile/META-INF/plexus/components.xml</descriptor>
<!--./maven-project-2.2.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-project/META-INF/plexus/components.xml</descriptor>
<!--./maven-settings-builder-3.1.1.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/maven-settings-builder/META-INF/plexus/components.xml</descriptor>
<!--./org.eclipse.sisu.plexus-0.0.0.M2a.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/sisu-plexus/META-INF/plexus/components.xml</descriptor>
<!--./plexus-cipher-1.4.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/plexus-cipher/META-INF/plexus/components.xml</descriptor>
<!--./plexus-interactivity-api-1.0-alpha-6.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/plexus-interactivity-api/META-INF/plexus/components.xml</descriptor>
<!--./plexus-sec-dispatcher-1.3.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/plexus-sec-dispatcher/META-INF/plexus/components.xml</descriptor>
<!--./wagon-ssh-1.0.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/wagon-ssh/META-INF/plexus/components.xml</descriptor>
<!--./wagon-ssh-common-1.0.jar.d/META-INF/plexus/components.xml-->
<descriptor>${project.build.directory}/extracted-sources/wagon-ssh-common/META-INF/plexus/components.xml</descriptor>
</descriptors>
</configuration>
</plugin>
Unfortunately the error message persists
So I guess my question is: How do I easily get a Maven instance from Plexus?
P.S. for completeness sake, I'm currently using the following dependencies:
[INFO] com.github.vogel612:dependency-analyzer:jar:0.0.1
[INFO] +- org.projectlombok:lombok:jar:1.16.16:compile
[INFO] +- commons-cli:commons-cli:jar:1.4:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.16:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.16:compile
[INFO] +- org.codehaus.plexus:plexus-utils:jar:3.0.24:compile
[INFO] +- org.eclipse.aether:aether-api:jar:1.1.0:compile
[INFO] +- org.eclipse.aether:aether-util:jar:1.1.0:compile
[INFO] +- org.eclipse.aether:aether-impl:jar:1.1.0:compile
[INFO] | \- org.eclipse.aether:aether-spi:jar:1.1.0:compile
[INFO] +- org.eclipse.aether:aether-connector-basic:jar:1.1.0:compile
[INFO] +- org.eclipse.aether:aether-transport-file:jar:1.1.0:compile
[INFO] +- org.eclipse.aether:aether-transport-http:jar:1.1.0:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.3.5:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.6.2:compile
[INFO] +- org.eclipse.aether:aether-transport-wagon:jar:1.1.0:compile
[INFO] | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0:compile
[INFO] +- org.apache.maven:maven-aether-provider:jar:3.1.0:compile
[INFO] | +- org.apache.maven:maven-model:jar:3.1.0:compile
[INFO] | +- org.apache.maven:maven-model-builder:jar:3.1.0:compile
[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.1.0:compile
[INFO] | +- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.0.0.M2a:compile
[INFO] | | +- javax.enterprise:cdi-api:jar:1.0:compile
[INFO] | | | +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] | | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | | +- com.google.guava:guava:jar:10.0.1:compile
[INFO] | | | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] | | +- org.sonatype.sisu:sisu-guice:jar:no_aop:3.1.0:compile
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | \- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.0.0.M2a:compile
[INFO] | | \- asm:asm:jar:3.3.1:compile
[INFO] | \- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] +- org.apache.maven.wagon:wagon-ssh:jar:1.0:compile
[INFO] | +- com.jcraft:jsch:jar:0.1.44-1:compile
[INFO] | \- org.apache.maven.wagon:wagon-ssh-common:jar:1.0:compile
[INFO] | \- org.codehaus.plexus:plexus-interactivity-api:jar:1.0-alpha-6:compile
[INFO] +- org.apache.maven:maven-core:jar:3.1.1:compile
[INFO] | +- org.apache.maven:maven-settings:jar:3.1.1:compile
[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.1.1:compile
[INFO] | +- org.apache.maven:maven-artifact:jar:3.1.1:compile
[INFO] | +- org.apache.maven:maven-plugin-api:jar:3.1.1:compile
[INFO] | +- org.codehaus.plexus:plexus-interpolation:jar:1.19:compile
[INFO] | +- org.codehaus.plexus:plexus-classworlds:jar:2.5.1:compile
[INFO] | \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] | \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] \- org.apache.maven:maven-project:jar:2.2.1:compile
[INFO] +- org.apache.maven:maven-profile:jar:2.2.1:compile
[INFO] +- org.apache.maven:maven-artifact-manager:jar:2.2.1:compile
[INFO] | \- backport-util-concurrent:backport-util-concurrent:jar:3.1:compile
[INFO] +- org.apache.maven:maven-plugin-registry:jar:2.2.1:compile
[INFO] \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:compile
[INFO] +- junit:junit:jar:3.8.1:compile
[INFO] \- classworlds:classworlds:jar:1.1-alpha-2:compile

It might have been helpful as a start to read the error message closely:
The missing Component is org.apache.maven.repository.RepositorySystem and not org.eclipse.aether.RepositorySystem. While the former was already included, the latter is only present in org.apache.maven:maven-compat.
Adding that to the dependencies (and including it's component definitions) fixes the immediate issue here. The intermediate result is currently a NoClassDefFoundError for Lorg/apache/maven/artifact/transform/ArtifactTransformationManager, which can be resolved by actually using the correct version of the dependency.
As the final step now an instance of org.eclipse.aether.RepositorySystem and one instance of org.eclipse.aether.impl.RemoteRepositoryManager needs to be registered, which can be accomplished using code along the following lines:
final ServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator()
.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class)
.addService(TransporterFactory.class, FileTransporterFactory.class)
.addService(TransporterFactory.class, HttpTransporterFactory.class);
// ...
container.addComponent(serviceLocator.lookup(RepositorySystem.class)
, RepositorySystem.class
, "default");
container.addComponent(serviceLocator.lookup(RemoteRepositoryManager.class)
, RemoteRepositoryManager.class
, "default");
And now we can finally have a maven-instance.

Related

NoSuchMethodError using spring-boot

I haven't changed its pom.xml for this project, but when I started the project recently, it reported this error: java.lang.NoSuchMethodError.
Seeing the error, it seems that it can't find the interface method I wrote.
2020-07-21 10:23:05.212 ERROR [main] ApiDescriptionReader::read[#87] : Skipping process path[/projects], method[addProject] as it has an error.java.lang.NoSuchMethodError: org.springframework.http.MediaType.equalsTypeAndSubtype(Lorg/springframework/util/MimeType;)Z
at springfox.documentation.builders.BodyParameterSpecificationProvider.lambda$create$0(BodyParameterSpecificationProvider.java:37)
... ...
I tried mvn clean install, it still doesn't work. This is the io.springfox dependency tree:
[INFO] +- org.springframework.retry:spring-retry:jar:1.2.4.RELEASE:compile
[INFO] | \- org.springframework:spring-core:jar:5.0.7.RELEASE:compile
[INFO] | \- org.springframework:spring-jcl:jar:5.0.7.RELEASE:compile
[INFO] +- org.mybatis.spring.boot:mybatis-spring-boot-starter:jar:2.0.0:compile
[INFO] | \- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.3.RELEASE:compile
[INFO] | \- org.springframework:spring-jdbc:jar:5.0.7.RELEASE:compile
[INFO] | \- org.springframework:spring-tx:jar:5.0.7.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-webflux:jar:2.0.3.RELEASE:compile
[INFO] | +- org.springframework:spring-web:jar:5.0.7.RELEASE:compile
[INFO] | \- org.springframework:spring-webflux:jar:5.0.7.RELEASE:compile
[INFO] \- org.springframework.plugin:spring-plugin-core:jar:2.0.0.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:5.0.7.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:5.0.7.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.0.7.RELEASE:compile
[INFO] \- org.springframework:spring-aop:jar:5.0.7.RELEASE:compile
[INFO] +- io.springfox:springfox-swagger2:jar:3.0.0-SNAPSHOT:compile
[INFO] | +- io.springfox:springfox-spi:jar:3.0.0-SNAPSHOT:compile
[INFO] | +- io.springfox:springfox-schema:jar:3.0.0-SNAPSHOT:compile
[INFO] | +- io.springfox:springfox-swagger-common:jar:3.0.0-SNAPSHOT:compile
[INFO] | +- io.springfox:springfox-spring-web:jar:3.0.0-SNAPSHOT:compile
[INFO] | \- io.springfox:springfox-spring-webmvc:jar:3.0.0-SNAPSHOT:compile
[INFO] +- io.springfox:springfox-swagger-ui:jar:3.0.0-SNAPSHOT:compile
[INFO] \- io.springfox:springfox-spring-webflux:jar:3.0.0-SNAPSHOT:compile
[INFO] \- io.springfox:springfox-core:jar:3.0.0-SNAPSHOT:compile
According to the documentation this method exists since spring 5.1.4
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/util/MimeType.html#equalsTypeAndSubtype-org.springframework.util.MimeType-
You can update the version of spring that you use or decrease the version of spring-fox

microservices: C:\....m2\repository\org\glassfish\jersey\core\jersey-client\2.22.1\jersey-client-2.22.1.jar; invalid LOC header (bad signature)

I was looking to developed the microservices example by following the link: https://github.com/bjedrzejewski/tasklist-service. When I simply compile the whole source code I faced compilation error, not sure why ? It looks to me something wrong with my .m2 home not so sure though.
The error coming for reference:-
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project tasklist-service: Compilation failure: Compilation failure:
[ERROR] error: error reading C:\Users\user\.m2\repository\org\glassfish\jersey\core\jersey-client\2.22.1\jersey-client-2.22.1.jar; invalid LOC header (bad signature)
[ERROR] error: error reading C:\Users\user\.m2\repository\org\eclipse\jetty\jetty-servlet\9.2.13.v20150730\jetty-servlet-9.2.13.v20150730.jar; invalid LOC header (bad signature)
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project tasklist-service: Compilation failure
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure
at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656)
at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 20 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I only updated pom.xml to use Java version 8, nothing special
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bjedrzejewski</groupId>
<artifactId>tasklist-service</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<dropwizard.version>0.9.1</dropwizard.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-core</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-common</artifactId>
<version>2.23.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.bjedrzejewski.tasklistservice.TaskListServiceApplication</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Also pom.xml dont have much entry of dependencies but still I see many jars files gets download why this so ?
E:\Advance Java\MicroServices\Git code\tasklist-service>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tasklist-service 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # tasklist-service ---
[INFO] bjedrzejewski:tasklist-service:jar:1.0-SNAPSHOT
[INFO] +- io.dropwizard:dropwizard-core:jar:0.9.1:compile
[INFO] | +- io.dropwizard:dropwizard-util:jar:0.9.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile
[INFO] | | +- com.google.guava:guava:jar:18.0:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.1:compile
[INFO] | | \- joda-time:joda-time:jar:2.9:compile
[INFO] | +- io.dropwizard:dropwizard-jackson:jar:0.9.1:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.6.3:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk7:jar:2.6.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-guava:jar:2.6.3:compile
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-afterburner:jar:2.6.3:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-joda:jar:2.6.3:compile
[INFO] | | +- org.slf4j:slf4j-api:jar:1.7.12:compile
[INFO] | | \- ch.qos.logback:logback-classic:jar:1.1.3:compile
[INFO] | +- io.dropwizard:dropwizard-validation:jar:0.9.1:compile
[INFO] | | +- org.hibernate:hibernate-validator:jar:5.2.2.Final:compile
[INFO] | | | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | | | +- org.jboss.logging:jboss-logging:jar:3.2.1.Final:compile
[INFO] | | | \- com.fasterxml:classmate:jar:1.1.0:compile
[INFO] | | \- org.glassfish:javax.el:jar:3.0.0:compile
[INFO] | +- io.dropwizard:dropwizard-configuration:jar:0.9.1:compile
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.6.3:compile
[INFO] | | | \- org.yaml:snakeyaml:jar:1.15:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | +- io.dropwizard:dropwizard-logging:jar:0.9.1:compile
[INFO] | | +- io.dropwizard.metrics:metrics-logback:jar:3.1.2:compile
[INFO] | | +- org.slf4j:jul-to-slf4j:jar:1.7.12:compile
[INFO] | | +- ch.qos.logback:logback-core:jar:1.1.3:compile
[INFO] | | +- org.slf4j:log4j-over-slf4j:jar:1.7.12:compile
[INFO] | | +- org.slf4j:jcl-over-slf4j:jar:1.7.12:compile
[INFO] | | \- org.eclipse.jetty:jetty-util:jar:9.2.13.v20150730:compile
[INFO] | +- io.dropwizard:dropwizard-metrics:jar:0.9.1:compile
[INFO] | +- io.dropwizard:dropwizard-jersey:jar:0.9.1:compile
[INFO] | | +- org.glassfish.jersey.core:jersey-server:jar:2.22.1:compile
[INFO] | | | +- org.glassfish.jersey.core:jersey-client:jar:2.22.1:compile
[INFO] | | | \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.22.1:compile
[INFO] | | +- org.glassfish.jersey.ext:jersey-metainf-services:jar:2.22.1:compile
[INFO] | | +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.22.1:compile
[INFO] | | +- io.dropwizard.metrics:metrics-jersey2:jar:3.1.2:compile
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.6.3:compile
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.6.3:compile
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.6.3:compile
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.22.1:compile
[INFO] | | | \- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.22.1:compile
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.2.13.v20150730:compile
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.2.13.v20150730:compile
[INFO] | | +- org.eclipse.jetty:jetty-webapp:jar:9.2.13.v20150730:compile
[INFO] | | | \- org.eclipse.jetty:jetty-xml:jar:9.2.13.v20150730:compile
[INFO] | | \- org.eclipse.jetty:jetty-continuation:jar:9.2.13.v20150730:compile
[INFO] | +- io.dropwizard:dropwizard-servlets:jar:0.9.1:compile
[INFO] | | \- io.dropwizard.metrics:metrics-annotation:jar:3.1.2:compile
[INFO] | +- io.dropwizard:dropwizard-jetty:jar:0.9.1:compile
[INFO] | | +- io.dropwizard.metrics:metrics-jetty9:jar:3.1.2:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.2.13.v20150730:compile
[INFO] | | | \- org.eclipse.jetty:jetty-security:jar:9.2.13.v20150730:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.2.13.v20150730:compile
[INFO] | | \- org.eclipse.jetty:jetty-http:jar:9.2.13.v20150730:compile
[INFO] | +- io.dropwizard:dropwizard-lifecycle:jar:0.9.1:compile
[INFO] | +- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] | +- io.dropwizard.metrics:metrics-jvm:jar:3.1.2:compile
[INFO] | +- io.dropwizard.metrics:metrics-servlets:jar:3.1.2:compile
[INFO] | | \- io.dropwizard.metrics:metrics-json:jar:3.1.2:compile
[INFO] | +- io.dropwizard.metrics:metrics-healthchecks:jar:3.1.2:compile
[INFO] | +- net.sourceforge.argparse4j:argparse4j:jar:0.6.0:compile
[INFO] | \- org.eclipse.jetty.toolchain.setuid:jetty-setuid-java:jar:1.0.3:compile
[INFO] \- org.glassfish.jersey.core:jersey-common:jar:2.23.2:compile
[INFO] +- javax.ws.rs:javax.ws.rs-api:jar:2.0.1:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] +- org.glassfish.jersey.bundles.repackaged:jersey-guava:jar:2.23.2:compile
[INFO] +- org.glassfish.hk2:hk2-api:jar:2.5.0-b05:compile
[INFO] | +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b05:compile
[INFO] | \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b05:compile
[INFO] +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b05:compile
[INFO] +- org.glassfish.hk2:hk2-locator:jar:2.5.0-b05:compile
[INFO] | \- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.860 s
[INFO] Finished at: 2016-09-13T23:39:38+05:30
[INFO] Final Memory: 17M/309M
[INFO] ------------------------------------------------------------------------
I've had experinced this issue and as per research this error mainly occurs if the jar file may be corrupted. Try removing the all content of your
C:\Users\[your username]\.m2\repository\ folder.
Then right click your project, select Maven, Update Project, check on Force Update of Snapshots/Releases. Or simply to go the location where logs says invalid LOC header (bad signature) and delete it manually. in Your scenario, you need to delete all from
C:\Users\user\.m2\repository\org\glassfish\jersey\core\jersey-client\2.22.1\
and
C:\Users\user\.m2\repository\org\eclipse\jetty\jetty-servlet\9.2.13.v20150730\
and again compile the code using mvn clean install -DskipTests

dependencies for same jar having different trees

I am trying to resolve an issue with a spring jar. I am using very old jars for A very old project.
For one project my dependency tree is having spring-core 2.0.1 and for the other it is having Spring-core 2.0.2 now. they both are coming as a dependency of one jar : spring-ws-core:jar:1.0-m3.
The issue I am having is the exception below: it turns out that the ClassUtils was changed from 2.0.1 to 2.0.2 and missed out this method. :
ERROR [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 94) Context initialization failed: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityLoadJob' defined in class path resource [dri-applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.getConstructorIfAvailable(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:443)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:245)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:140)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:156)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173)
at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:195)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:100)
at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:82)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Caused by: java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.getConstructorIfAvailable(Ljava/lang/Class;[Ljava/lang/Class;)Ljava/lang/reflect/Constructor;
at org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean.<clinit>(MethodInvokingJobDetailFactoryBean.java:73)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:84)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:60)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:640)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:626)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:381)
... 20 more
[INFO] com.sar.registry:MyServlet:war:1.0-SNAPSHOT
[INFO] +- com.sar.registry:DirectRegistry:jar:1.0-SNAPSHOT:compile
[INFO] | +- com.sar.common:Common-Utils:jar:SNAPSHOT:compile
[INFO] | +- com.sar.common:Common-Integration:jar:SNAPSHOT:compile
[INFO] | +- org.springframework:spring:jar:2.0.1:compile
***[INFO] | +- org.springframework.ws:spring-ws-core:jar:1.0-m3:compile***
[INFO] | | +- org.springframework.ws:spring-xml:jar:1.0-m3:compile
[INFO] | | +- org.springframework:spring-context:jar:2.0.1:compile
[INFO] | | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | | +- org.springframework:spring-web:jar:2.0.2:compile
[INFO] | | +- org.springframework:spring-webmvc:jar:2.0.2:compile
[INFO] | | | \- org.springframework:spring-support:jar:2.0.2:compile
[INFO] | | +- stax:stax-api:jar:1.0:compile (version managed from 1.0.1)
[INFO] | | +- wsdl4j:wsdl4j:jar:1.6.1:compile
***[INFO] | | +- org.springframework:spring-core:jar:2.0.1:compile
[INFO] | | \- org.springframework:spring-beans:jar:2.0.1:compile***
[INFO] | +- org.springframework.ws:spring-oxm:jar:1.0-m3:compile
[INFO] | +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] | +- xml-security:xmlsec:jar:1.3.0:compile
[INFO] | +- wss4j:wss4j:jar:1.5.0:compile
[INFO] | +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.16:provided (scope managed from compile)
[INFO] | | \- org.jvnet.mimepull:mimepull:jar:1.7:provided
[INFO] | +- quartz:quartz:jar:1.5.2:compile
[INFO] | \- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] +- com.sar.registry:MyAppApi:jar:1.0-SNAPSHOT:compile
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- net.sf.saxon:saxon:jar:8.7:runtime
[INFO] +- org.springframework:spring-jmx:jar:2.0.1:runtime
[INFO] +- net.sf.saxon:saxon-dom:jar:8.7:runtime
[INFO] +- axis:axis:jar:1.4:runtime
[INFO] | +- axis:axis-wsdl4j:jar:1.5.1:runtime
[INFO] | \- commons-discovery:commons-discovery:jar:0.2:runtime
[INFO] +- taglibs:standard:jar:1.1.2:runtime
[INFO] +- javax.servlet:jstl:jar:1.1.2:runtime
[INFO] +- org.springframework:spring-mock:jar:2.0.1:test
[INFO] | \- junit:junit:jar:3.8.1:test
[INFO] +- xmlunit:xmlunit:jar:1.0:test
[INFO] \- hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] ------------------------------------------------------------------------
and for the other:
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) # MyApp ---
[INFO] com.sar.registry:MyApp:jar:1.0-SNAPSHOT
[INFO] +- com.sar.registry:MyAppApi:jar:1.0-SNAPSHOT:compile
[INFO] +- com.sar.common:Common-Utils:jar:SNAPSHOT:compile
[INFO] +- com.sar.common:Common-Integration:jar:SNAPSHOT:compile
[INFO] +- org.springframework:spring:jar:2.0.1:compile
***[INFO] +- org.springframework.ws:spring-ws-core:jar:1.0-m3:compile***
[INFO] | +- org.springframework.ws:spring-xml:jar:1.0-m3:compile
[INFO] | +- org.springframework:spring-context:jar:2.0.2:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | +- org.springframework:spring-web:jar:2.0.2:compile
[INFO] | +- org.springframework:spring-webmvc:jar:2.0.2:compile
[INFO] | | \- org.springframework:spring-support:jar:2.0.2:compile
[INFO] | +- stax:stax-api:jar:1.0:compile (version managed from 1.0.1)
[INFO] | +- wsdl4j:wsdl4j:jar:1.6.1:compile
***[INFO] | +- org.springframework:spring-core:jar:2.0.2:compile
[INFO] | \- org.springframework:spring-beans:jar:2.0.2:compile***
[INFO] +- org.springframework.ws:spring-oxm:jar:1.0-m3:compile
[INFO] +- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] +- xml-security:xmlsec:jar:1.3.0:compile
[INFO] +- wss4j:wss4j:jar:1.5.0:compile
[INFO] +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.16:compile
[INFO] | \- org.jvnet.mimepull:mimepull:jar:1.7:compile
[INFO] +- quartz:quartz:jar:1.5.2:compile
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- log4j:log4j:jar:1.2.8:test
[INFO] +- xmlunit:xmlunit:jar:1.0:test
[INFO] +- hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] +- org.springframework:spring-mock:jar:2.0.1:test
[INFO] +- xerces:xercesImpl:jar:2.8.1:test
[INFO] +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] +- net.sf.saxon:saxon:jar:8.7:test (scope not updated to runtime)
[INFO] +- net.sf.saxon:saxon-dom:jar:8.7:test
[INFO] \- axis:axis:jar:1.4:test
[INFO] +- org.apache.axis:axis-jaxrpc:jar:1.4:test
[INFO] +- org.apache.axis:axis-saaj:jar:1.4:test
[INFO] +- axis:axis-wsdl4j:jar:1.5.1:test
[INFO] \- commons-discovery:commons-discovery:jar:0.2:test
in my poms, I am not defining any versions for Spring-beans and Spring-core the only version I have defined is in the parent Pom which is org.springframework.ws:spring-ws-core:jar:1.0-m3:compile
Now how can two projects having the same jar can have different dependent jars altogether. I am on Maven3, wildfly9, java8.
Also, Somehow and strangely, the same war file works fine on my local windows wildfly9 but it gives me error on a SunOS and Linux machine.
Edit:
I got the dependencyTree Idea from NoSuchMethodError for XmlSchemaCollection.read()
and using that I found the two jars. As Harini suggested, I had already tried exclusion of the dependency and it still didn't work So I just refactored my code to have only one src and that too in the war (In wildfly war is loaded in its own classloader with its libs) So after refactoring as well, I got the same issue:
How I got to know that it was the jar issue was I did a verbose on my jvm and saw this:
[Loaded org.springframework.util.ClassUtils from vfs:/content/DirectRegistryServlet-1.0-SNAPSHOT.war/WEB-INF/lib/spring-core-2.0.1.jar]
In the spring-ws-core:jar:1.0-m3 dependency exclude the spring-core version which you are not using.Check it out for Dependency Exclusions.
https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
Upon looking at the code of org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean which I am using which is actually the one causing the issue it turns out that in spring 2.0.1 this FactoryBean does not have any mention of the ClassUtils.getConstructorIfAvailable which is good. It is the Spring-2.0.2 OR spring-support-2.0.2.jar That also has this class with this line where this call is.
(I was looking at the wrong class as the issue the issue was MethodInvokingJobDetailFactoryBean coming from a different jar instead of coming from spring-2.0.1.jar, Spring-ws-2.0.1actually uses spring-mvc which uses spring-support2.0.2.jar which had the same MethodInvokingJobDetailFactoryBean ) SO I solved it: Made only one library to get the MethodInvokingJobDetailFactoryBean removed the library or excluded the library that also had this class and solved it.
Strangely I cant understand how on windows it was working without an issue and on Linux and unix it gave an issue.

PowerMock: invalid constant type: 18 [duplicate]

Description:
I am trying to test a static method from a class. I am using powerMock (1.6.2) + mockito (1.10.19) for mocking along with Junit4 (4.12) & java8.
Issue:
Getting the error: "Failed to transform class with name com.gs.ops.domain.StaticClass Reason: java.io.IOException: invalid constant type: 18"
Solutions Tried:
Googled threads for issue on with powermock - mockito & java-8
Excluded java assist from powermock and added java assist 3.19.0-GA
Tried different versions of powermock (1.5.4, 1.6.2...)
Below is the exception stack trace:
java.lang.IllegalStateException: Failed to transform class with name com.StaticClass. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:266)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:145)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:203)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:110)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
at javassist.expr.NewExpr$ProceedForNew.setReturnType(NewExpr.java:243)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:146)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
at javassist.compiler.TypeChecker.atVariableAssign(TypeChecker.java:248)
at javassist.compiler.TypeChecker.atAssignExpr(TypeChecker.java:217)
at javassist.compiler.ast.AssignExpr.accept(AssignExpr.java:38)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:329)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:404)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:354)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.Javac.compileStmnt(Javac.java:568)
at javassist.expr.NewExpr.replace(NewExpr.java:206)
at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:418)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:211)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtClassType.instrument(CtClassType.java:1374)
at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:74)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:251)
... 24 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:149)
at javassist.bytecode.ClassFile.read(ClassFile.java:737)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:108)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
... 49 more
Pom file:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
</dependency>
Powermock 1.6.3 uses javassist 3.15.2-GA which does not support certain types. Using 3.18.2-GA javassist worked for me. You may want to override dependency in your project.
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
You may face another problem for which the solution lies here Mockito + PowerMock LinkageError while mocking system class
Hope this helps.
So there seems to be issue with javassist (bytecode toolkit) prior to 3.18.2, as there's a resolved JIRA ticket-223.
1 - To find javassist version in your pom.xml, can use mvn dependency task
$ mvn dependency:tree | grep javassist
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
which is used by the powermock-module-junit4-rule ,
[INFO] +- org.powermock:powermock-module-junit4-rule:jar:1.4.9:test
[INFO] | +- org.powermock:powermock-classloading-base:jar:1.4.9:test
[INFO] | \- org.powermock:powermock-core:jar:1.4.9:compile
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
2 - So, updating the javassist version by explicitly to any versions >= 3.18.2 should work.
As, in my case, I am using use 3.20.0-GA
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
Working eg. with scalatest
#PowerMockIgnore(Array("javax.management.*"))
#RunWith(classOf[PowerMockRunner])
#PrepareForTest(Array(classOf[Configurator]))
class LogServiceSpec {
#Test
def initialises_log4j2_on_each_instance_call() {
PowerMockito.mockStatic(classOf[Configurator])
val logService1 = new LogService
PowerMockito.verifyStatic(Mockito.times(1))
Configurator.initialize(Matchers.anyString(), Matchers.eq("log4j.config"))
}
}
This is caused because of the conflict of dependencies. Resolving the dependency conflicts is one way to resolve this issue and the other way is to reorder <dependency></dependency> elements in your pom.xml. Move the powermock dependency declarations to the top of the <dependencies></dependencies> section. This is a complete hack and the right way to resolve it would be to resolve the dependency conflicts.
To identify those conflict you may use the command "mvn dependency:tree". Here is the dependency tree for my application for which I came across this same problem. Notice that there are two dependencies of "javassist" in the tree.
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] | \- org.objenesis:objenesis:jar:2.1:compile
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:compile
[INFO] | <span style="background-color: #FFFF00">| \- org.javassist:javassist:jar:3.20.0-GA:compile</span>
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:compile
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:compile
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.14:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.14:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.apache.struts:struts2-core:jar:2.3.16.3-atlassian-6:provided
[INFO] | | \- ognl:ognl:jar:3.0.6:provided
<span style="background-color: #FFFF00">
[INFO] | | \- javassist:javassist:jar:3.11.0.GA:provided</span>
[INFO] | +- com.atlassian:webwork-compat:jar:1.24:provided
[INFO] | +- org.freemarker:freemarker:jar:2.3.16-atlassian-34:provided
[INFO] | | \- logkit:logkit:jar:1.2:provided
[INFO] | +- opensymphony:sitemesh:jar:2.5-atlassian-6:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- org.tuckey:urlrewritefilter:jar:4.0.3:provided
[INFO] | +- velocity-tools:velocity-tools:jar:1.2:provided
[INFO] | +- commons-dbutils:commons-dbutils:jar:1.3:provided
[INFO] | +- org.hamcrest:hamcrest-all:jar:1.3:provided
[INFO] | +- com.atlassian.bamboo:atlassian-user-crowd-provider:jar:5.10.0:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-client-rest:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:crowd-integration-client-common:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.security:atlassian-cookie-tools:jar:3.2:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-api:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:embedded-crowd-api:jar:2.7.2:provided
[INFO] | | +- com.atlassian.user:atlassian-user-api:jar:4.1.1:provided
[INFO] | | | \- com.opensymphony.propertyset:api:jar:1.6.0-m1:provided
[INFO] | | +- com.atlassian.user:atlassian-user-ldap:jar:4.1.1:provided
[INFO] | | +- org.acegisecurity:acegi-security:jar:1.0.4:provided
[INFO] | | | \- oro:oro:jar:2.0.8:provided
[INFO] | | \- com.atlassian.crowd:crowd-integration-seraph25:jar:2.7.2:provided
[INFO] | +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] | +- com.atlassian.core:atlassian-core:jar:5.0.2:provided
[INFO] | | \- com.atlassian.image:atlassian-image-consumer:jar:1.0.1:provided
[INFO] | +- org.apache.maven:maven-embedder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-settings:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-model-builder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-compat:jar:3.0.4:provided
[INFO] | | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:provided
[INFO] | | +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:provided
[INFO] | | | \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:provided
[INFO] | | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:provided
[INFO] | | +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:provided
[INFO] | | +- org.sonatype.plexus:plexus-cipher:jar:1.7:provided
[INFO] | | \- commons-cli:commons-cli:jar:1.2:provided
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:provided
[INFO] | +- com.octo.captcha:jcaptcha:jar:2.0-alpha-1:provided
[INFO] | +- com.octo.captcha:jcaptcha-api:jar:2.0-alpha-1:provided
[INFO] | +- com.jhlabs:filters:jar:2.0.235:provided
[INFO] | +- org.apache.struts:struts2-sitemesh-plugin:jar:2.1.8.1:provided
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.10:provided
[INFO] | +- com.atlassian.plugins:atlassian-plugins-schema:jar:4.0.5:provided
[INFO] | | \- com.atlassian.plugins:atlassian-plugins-osgi:jar:4.0.5:provided
[INFO] | | +- com.atlassian.plugins:atlassian-plugins-osgi-events:jar:4.0.5:provided
[INFO] | | +- biz.aQute.bnd:biz.aQute.bndlib:jar:2.4.1:provided
[INFO] | | +- org.apache.felix:org.apache.felix.framework:jar:4.2.1:provided
[INFO] | | \- org.twdata.pkgscanner:package-scanner:jar:0.9.5:provided
[INFO] | \- xerces:xercesImpl:jar:2.11.0:provided
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:provided
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- info.cukes:cucumber-java:jar:1.2.4:test
[INFO] | \- info.cukes:cucumber-core:jar:1.2.4:test
[INFO] | +- info.cukes:cucumber-html:jar:0.2.3:test
[INFO] | +- info.cukes:cucumber-jvm-deps:jar:1.0.5:test
[INFO] | \- info.cukes:gherkin:jar:2.12.2:test
[INFO] +- info.cukes:cucumber-junit:jar:1.2.4:test
[INFO] +- com.atlassian.plugins:atlassian-plugins-osgi-testrunner:jar:1.2.3:test
[INFO] | +- org.apache.wink:wink-client:jar:1.1.3-incubating:test
[INFO] | | +- org.apache.wink:wink-common:jar:1.1.3-incubating:test
[INFO] | | | \- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0:test
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.2:test
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.1.1:test
[INFO] | +- commons-io:commons-io:jar:1.4:provided
[INFO] | \- com.atlassian.upm:upm-api:jar:2.15:test
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2-atlassian-1:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile
[INFO] +- org.json:json:jar:20090211:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
I hope this helps.
In my case, a "java.io.IOException: invalid constant type: 18" was caused by multiple versions of javassist libraries in my classpath - both 3.12.1.GA and 3.18.2-GA. The problem disappeared when i removed the older one.
Not really an answer! I got a similar error when running a Maven build with JDK8 and generating Java6 byte code. My pom looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
<maxmem>2000m</maxmem>
<fork>true</fork>
</configuration>
</plugin>
When I reverted to JDK6 I no longer got the error.
In my case JRE System Library --> Execution Environment was set up on JavaSE-1.7, but the only installed JRE was JRE1.8. So it was pointing to java 8 in place of java 7. Once I moved to java 7 it start working fine for me.
This issue is related to a compatibility issue with Java 8. could you execute your tests on java 7 ?
Run "mvn dependency:tree | grep javassist" on terminal. If javaassist dependency is being shown in non test and test libraries. Now you only have to exclude it during runtime for tests. So the way to do this is adding a build plugin on the lines of:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>javassist:javassist</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
Please note the classpathDependencyExcludes might change for you based on your javassist version.

Powermock - java.lang.IllegalStateException: Failed to transform class

Description:
I am trying to test a static method from a class. I am using powerMock (1.6.2) + mockito (1.10.19) for mocking along with Junit4 (4.12) & java8.
Issue:
Getting the error: "Failed to transform class with name com.gs.ops.domain.StaticClass Reason: java.io.IOException: invalid constant type: 18"
Solutions Tried:
Googled threads for issue on with powermock - mockito & java-8
Excluded java assist from powermock and added java assist 3.19.0-GA
Tried different versions of powermock (1.5.4, 1.6.2...)
Below is the exception stack trace:
java.lang.IllegalStateException: Failed to transform class with name com.StaticClass. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:266)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:145)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:203)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:110)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
at javassist.expr.NewExpr$ProceedForNew.setReturnType(NewExpr.java:243)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:146)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
at javassist.compiler.TypeChecker.atVariableAssign(TypeChecker.java:248)
at javassist.compiler.TypeChecker.atAssignExpr(TypeChecker.java:217)
at javassist.compiler.ast.AssignExpr.accept(AssignExpr.java:38)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:329)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:404)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:354)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.Javac.compileStmnt(Javac.java:568)
at javassist.expr.NewExpr.replace(NewExpr.java:206)
at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:418)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:211)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtClassType.instrument(CtClassType.java:1374)
at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:74)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:251)
... 24 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:149)
at javassist.bytecode.ClassFile.read(ClassFile.java:737)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:108)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
... 49 more
Pom file:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
</dependency>
Powermock 1.6.3 uses javassist 3.15.2-GA which does not support certain types. Using 3.18.2-GA javassist worked for me. You may want to override dependency in your project.
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
You may face another problem for which the solution lies here Mockito + PowerMock LinkageError while mocking system class
Hope this helps.
So there seems to be issue with javassist (bytecode toolkit) prior to 3.18.2, as there's a resolved JIRA ticket-223.
1 - To find javassist version in your pom.xml, can use mvn dependency task
$ mvn dependency:tree | grep javassist
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
which is used by the powermock-module-junit4-rule ,
[INFO] +- org.powermock:powermock-module-junit4-rule:jar:1.4.9:test
[INFO] | +- org.powermock:powermock-classloading-base:jar:1.4.9:test
[INFO] | \- org.powermock:powermock-core:jar:1.4.9:compile
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
2 - So, updating the javassist version by explicitly to any versions >= 3.18.2 should work.
As, in my case, I am using use 3.20.0-GA
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
Working eg. with scalatest
#PowerMockIgnore(Array("javax.management.*"))
#RunWith(classOf[PowerMockRunner])
#PrepareForTest(Array(classOf[Configurator]))
class LogServiceSpec {
#Test
def initialises_log4j2_on_each_instance_call() {
PowerMockito.mockStatic(classOf[Configurator])
val logService1 = new LogService
PowerMockito.verifyStatic(Mockito.times(1))
Configurator.initialize(Matchers.anyString(), Matchers.eq("log4j.config"))
}
}
This is caused because of the conflict of dependencies. Resolving the dependency conflicts is one way to resolve this issue and the other way is to reorder <dependency></dependency> elements in your pom.xml. Move the powermock dependency declarations to the top of the <dependencies></dependencies> section. This is a complete hack and the right way to resolve it would be to resolve the dependency conflicts.
To identify those conflict you may use the command "mvn dependency:tree". Here is the dependency tree for my application for which I came across this same problem. Notice that there are two dependencies of "javassist" in the tree.
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] | \- org.objenesis:objenesis:jar:2.1:compile
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:compile
[INFO] | <span style="background-color: #FFFF00">| \- org.javassist:javassist:jar:3.20.0-GA:compile</span>
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:compile
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:compile
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.14:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.14:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.apache.struts:struts2-core:jar:2.3.16.3-atlassian-6:provided
[INFO] | | \- ognl:ognl:jar:3.0.6:provided
<span style="background-color: #FFFF00">
[INFO] | | \- javassist:javassist:jar:3.11.0.GA:provided</span>
[INFO] | +- com.atlassian:webwork-compat:jar:1.24:provided
[INFO] | +- org.freemarker:freemarker:jar:2.3.16-atlassian-34:provided
[INFO] | | \- logkit:logkit:jar:1.2:provided
[INFO] | +- opensymphony:sitemesh:jar:2.5-atlassian-6:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- org.tuckey:urlrewritefilter:jar:4.0.3:provided
[INFO] | +- velocity-tools:velocity-tools:jar:1.2:provided
[INFO] | +- commons-dbutils:commons-dbutils:jar:1.3:provided
[INFO] | +- org.hamcrest:hamcrest-all:jar:1.3:provided
[INFO] | +- com.atlassian.bamboo:atlassian-user-crowd-provider:jar:5.10.0:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-client-rest:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:crowd-integration-client-common:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.security:atlassian-cookie-tools:jar:3.2:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-api:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:embedded-crowd-api:jar:2.7.2:provided
[INFO] | | +- com.atlassian.user:atlassian-user-api:jar:4.1.1:provided
[INFO] | | | \- com.opensymphony.propertyset:api:jar:1.6.0-m1:provided
[INFO] | | +- com.atlassian.user:atlassian-user-ldap:jar:4.1.1:provided
[INFO] | | +- org.acegisecurity:acegi-security:jar:1.0.4:provided
[INFO] | | | \- oro:oro:jar:2.0.8:provided
[INFO] | | \- com.atlassian.crowd:crowd-integration-seraph25:jar:2.7.2:provided
[INFO] | +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] | +- com.atlassian.core:atlassian-core:jar:5.0.2:provided
[INFO] | | \- com.atlassian.image:atlassian-image-consumer:jar:1.0.1:provided
[INFO] | +- org.apache.maven:maven-embedder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-settings:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-model-builder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-compat:jar:3.0.4:provided
[INFO] | | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:provided
[INFO] | | +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:provided
[INFO] | | | \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:provided
[INFO] | | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:provided
[INFO] | | +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:provided
[INFO] | | +- org.sonatype.plexus:plexus-cipher:jar:1.7:provided
[INFO] | | \- commons-cli:commons-cli:jar:1.2:provided
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:provided
[INFO] | +- com.octo.captcha:jcaptcha:jar:2.0-alpha-1:provided
[INFO] | +- com.octo.captcha:jcaptcha-api:jar:2.0-alpha-1:provided
[INFO] | +- com.jhlabs:filters:jar:2.0.235:provided
[INFO] | +- org.apache.struts:struts2-sitemesh-plugin:jar:2.1.8.1:provided
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.10:provided
[INFO] | +- com.atlassian.plugins:atlassian-plugins-schema:jar:4.0.5:provided
[INFO] | | \- com.atlassian.plugins:atlassian-plugins-osgi:jar:4.0.5:provided
[INFO] | | +- com.atlassian.plugins:atlassian-plugins-osgi-events:jar:4.0.5:provided
[INFO] | | +- biz.aQute.bnd:biz.aQute.bndlib:jar:2.4.1:provided
[INFO] | | +- org.apache.felix:org.apache.felix.framework:jar:4.2.1:provided
[INFO] | | \- org.twdata.pkgscanner:package-scanner:jar:0.9.5:provided
[INFO] | \- xerces:xercesImpl:jar:2.11.0:provided
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:provided
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- info.cukes:cucumber-java:jar:1.2.4:test
[INFO] | \- info.cukes:cucumber-core:jar:1.2.4:test
[INFO] | +- info.cukes:cucumber-html:jar:0.2.3:test
[INFO] | +- info.cukes:cucumber-jvm-deps:jar:1.0.5:test
[INFO] | \- info.cukes:gherkin:jar:2.12.2:test
[INFO] +- info.cukes:cucumber-junit:jar:1.2.4:test
[INFO] +- com.atlassian.plugins:atlassian-plugins-osgi-testrunner:jar:1.2.3:test
[INFO] | +- org.apache.wink:wink-client:jar:1.1.3-incubating:test
[INFO] | | +- org.apache.wink:wink-common:jar:1.1.3-incubating:test
[INFO] | | | \- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0:test
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.2:test
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.1.1:test
[INFO] | +- commons-io:commons-io:jar:1.4:provided
[INFO] | \- com.atlassian.upm:upm-api:jar:2.15:test
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2-atlassian-1:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile
[INFO] +- org.json:json:jar:20090211:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
I hope this helps.
In my case, a "java.io.IOException: invalid constant type: 18" was caused by multiple versions of javassist libraries in my classpath - both 3.12.1.GA and 3.18.2-GA. The problem disappeared when i removed the older one.
Not really an answer! I got a similar error when running a Maven build with JDK8 and generating Java6 byte code. My pom looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
<maxmem>2000m</maxmem>
<fork>true</fork>
</configuration>
</plugin>
When I reverted to JDK6 I no longer got the error.
In my case JRE System Library --> Execution Environment was set up on JavaSE-1.7, but the only installed JRE was JRE1.8. So it was pointing to java 8 in place of java 7. Once I moved to java 7 it start working fine for me.
This issue is related to a compatibility issue with Java 8. could you execute your tests on java 7 ?
Run "mvn dependency:tree | grep javassist" on terminal. If javaassist dependency is being shown in non test and test libraries. Now you only have to exclude it during runtime for tests. So the way to do this is adding a build plugin on the lines of:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>javassist:javassist</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
Please note the classpathDependencyExcludes might change for you based on your javassist version.

Categories