java.lang.NoSuchMethodError: org.jboss.arquillian.test.spi.event.enrichment.BeforeEnrichment: method <init>()V not found - jboss-arquillian

I am trying to test my ReST service with arquillian and wildfly 10.0 and I am getting the above error.
There must be a problem with versions of the various libraries I am using but I can't figure out which one. My dependencies are (snippet from my ivy.xml file):
<dependency org="org.jboss.arquillian" name="arquillian-bom" rev="1.1.11.Final" conf="test->default"/>
<dependency org="org.jboss.arquillian.junit" name="arquillian-junit-container" rev="1.1.2.Final" conf="test->default"/>
<dependency org="org.wildfly.arquillian" name="wildfly-arquillian-container-embedded" rev="2.0.0.Final" conf="test->default"/>
<dependency org="org.wildfly.security" name="wildfly-security-manager" rev="1.1.2.Final" conf="test->default"/>
<dependency org="org.jboss.shrinkwrap.resolver" name="shrinkwrap-resolver-depchain" rev="2.2.4" conf="test->default"/>
<dependency org="org.jboss.arquillian.extension" name="arquillian-rest-client-impl-3x" rev="1.0.0.Final-SNAPSHOT" conf="test->default"/>
Any ideas?

So the arquillian-junit-container revision has to be the same as that of arquillian-bom (in this case 1.1.11.Final)

Related

Ivy : dependency between 2 dependencies

I am looking for a way to declare "a dependency between 2 dependencies".
For instance, in my module, I have in ivy.xml the following lines :
<dependencies>
<dependency org="org.slf4j" name="slf4j-api" rev="${slf4japiversion}"/>
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="test->default"/>
</dependencies>
My problem is that logback-classic 1.0.13 depends on slf4j-api 1.7.5 and my module depends on 1.6.6 (value of slf4japiversion).
I can't change slf4japiversion but in the future it could be upgraded by someone else.
Is there a way to declare the dependency on logback to retrieve the version compatible with my slf4j-api version ?
You can specify an override directive to force resolution to a particular version of a dependency:
<dependencies>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" conf="compile->default"/>
<dependency org="ch.qos.logback" name="logback-classic" rev="1.0.13" conf="runtime->default"/>
<override org="org.slf4j" module="slf4j-api" rev="1.6.6"/>
</dependencies>
A word of warning, when downgrading dependencies. If logback uses a feature only supported by version 1.7.5 then the solution will not work. It's far more likely a library is backwardly compatible.

Ivy Retrieve with Classifiers

I have the following ivy.xml:
<ivy-module version="1.0"
xmlns:maven="http://maven.apache.org">
<configurations>
...
</configurations>
<dependencies>
<dependency org="com.foo" name="fubur"
rev="1.3" conf="runtime->default"/>
<dependency org="com.snafu" name="barfu"
rev="1.4" conf="runtime->default">
<artifact name="barfu"
maven:classifier="ID_10T"
type="jar" ext="jar"/>
</dependency>
</dependencies>
</ivy-module>
In my build.xml, I want to retrieve all of my jars for the war I'm building:
<ivy:retrieve
pattern="${lib.dir}/[artifact]-[classifier]-[revision].[ext]"
conf="runtime"/>
No, that won't work... There's no classifier in fubar-1.3.jar. It will download as fubar--1.3.jar
<ivy:retrieve
pattern="${lib.dir}/[artifact]-[revision].[ext]"
conf="runtime"/>
That's no good either. barfu-ID_10T-1.4.jar will download as barfu-1.4.jar.
I would like the jars in my war to be included as barfu-ID_10T-1.4.jar and fubar-1.3-jar`. Is there an easy way of doing that? I know I could create two different configurations, but that is overkill. I'd rather just have the jars miss-named since it really doesn't affect the war itself.
Use parentheses to specify optional components of an attribute pattern:
<ivy:retrieve
pattern="${lib.dir}/[artifact](-[classifier])-[revision].[ext]"
conf="runtime"/>

Retrieve Specific jar to a Folder

I was to retrieve a jar from ivy cache to a lib folder, below is the ivy.xml code:
<configurations>
<conf name="specificFolder" description="add jar to web-inf/lib folder"/>
</configurations>
<dependencies>
<dependency org="javax.servlet" name="servlet-api" rev="2.4" transitive="false" conf="specificFolder"/>
<dependency org="org.springframework" name="spring-beans" rev="2.5.5" transitive="false" />
<dependency org="org.springframework" name="spring-webmvc" rev="2.5.5" transitive="false" />
<dependency org="org.springframework" name="spring-web" rev="2.5.5" transitive="false" />
<dependency org="org.springframework" name="spring-context" rev="2.5.5" transitive="false" />
<dependency org="org.springframework" name="spring" rev="1.2.6" transitive="false" />
then this is ant target:
<target name="test">
<ivy:retrieve pattern="lib/[artifact](.[ext])" sync="true" type="jar" conf="specificFolder"/>
</target>
But I got "Unresolved Dependency", this anything I am doing wrong?
I reproduced your problem and here is the relevant error message:
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: UNRESOLVED DEPENDENCIES ::
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: javax.servlet#servlet-api;2.4: configuration not found in javax.servlet#servlet-api;2.4: 'specificFolder'. It was required from com.myspotontheweb#demo;????? specificFolder
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
The root cause is the following dependency declaration:
<dependency org="javax.servlet" name="servlet-api" ... conf="specificFolder"/>
While the configuration exists in your module it does not exist in the remote Maven module. For more details on how see the following answer:
How are maven scopes mapped to ivy configurations by ivy
Working example
ivy.xml
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="specificFolder" description="add jar to web-inf/lib folder"/>
</configurations>
<dependencies>
<dependency org="javax.servlet" name="servlet-api" rev="2.4" conf="specificFolder->master"/>
<dependency org="org.springframework" name="spring-beans" rev="2.5.5" conf="specificFolder->master"/>
<dependency org="org.springframework" name="spring-webmvc" rev="2.5.5" conf="specificFolder->master"/>
<dependency org="org.springframework" name="spring-web" rev="2.5.5" conf="specificFolder->master"/>
<dependency org="org.springframework" name="spring-context" rev="2.5.5" conf="specificFolder->master"/>
<dependency org="org.springframework" name="spring" rev="1.2.6" conf="specificFolder->master"/>
</dependencies>
</ivy-module>
Notes:
This example uses configuration mappings instead of "transitive=false". The local configuration is "specificFolder" and the remote configuration is the special "master". "master" is provided by Maven modules and means the remote artifact with no dependencies. I think this approach is simpler once it's understood how configurations work. (Very powerful concept in Maven)
what does the little arrow -> do in the ivy dependency section?

Publish Only Dependencies

I want to publish the dependencies of a module seperately from the jar artifact of the module.
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
<info organisation="com.mycompany" module="platform" />
<configurations defaultconfmapping="release->*;compile->*" defaultconf="release">
<conf name="release" />
<conf name="compile" extends="release" />
</configurations>
<publications>
<artifact name="platform-api" type="jar" ext="jar" />
</publications>
<dependencies>
<dependency org="com.google.inject" name="guice" rev="3.0" />
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" />
<dependency org="com.google.guava" name="guava" rev="13.0-rc1" conf="compile" />
<dependency org="log4j" name="log4j" rev="1.2.17" conf="compile" />
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6" conf="compile" />
</dependencies>
</ivy-module>
For the configuration above, I want an artifact that includes guice & slf4j-api jars only, without the platform-api.jar. My current solution is to define two dependencies in the dependent module, one transitive and other not:
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" conf="myconf->release">
<exclude org="com.mycompany" />
</dependency>
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" transitive="false" conf="myotherconf->release" />
But this solution causes problems when the third module is dependent on both of these modules, and it is just ugly.
Try this instead:
<ivy-module version="2.0">
<info organisation="com.mycompany" module="platform" />
<configurations>
<conf name="default" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
<conf name="master" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
<conf name="compile" description="Compile dependencies"/>
<conf name="runtime" description="Runtime dependencies, includes compile dependencies" extends="compile"/>
</configurations>
<publications>
<artifact name="platform-api" type="jar" ext="jar" conf="master"/>
</publications>
<dependencies>
<!-- Compile dependencies -->
<dependency org="com.google.inject" name="guice" rev="3.0" conf="compile->default"/>
<dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" conf="compile->default"/>
<dependency org="com.google.guava" name="guava" rev="13.0-rc1" conf="compile->default" />
<!-- Runtime dependencies -->
<dependency org="log4j" name="log4j" rev="1.2.17" conf="runtime->default" />
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6" conf="runtime->default" />
</dependencies>
</ivy-module>
Notes:
Note the "extends" attribute on the configurations, used to create larger sets of jars.
I recommend remove the default configuration mapping and explicitly set a conf mapping on each depedency. Simpler and ultimately easier to understand in my opinion (less magic)
Now that your module has separate configurations for the published artifacts and it's runtime dependencies a single dependency declaration can be used as follows to map these to separate local configurations:
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" conf="myconf->runtime;myotherconf->master" />
I think, what you are looking for is actually two projects sharing the same dependencies. (and by coincidence one of them is using the other as well).
Did you consider using extends http://ant.apache.org/ivy/history/latest-milestone/ivyfile/extends.html with:
extendType="dependencies".
Then you would have your platform extending the the parent-ivy.xml with the dependencies. And your Other project extending the same parent-ivy.xml file for the same dependencies.
I'm not sure if this is enough. Since the configurations will play role here. But maybe it's a start.

Keep Ivy from including test dependencies

Consider an ivy.xml like the following:
<ivy-module version="2.0">
<info organisation="com.foo" module="FooBar" />
<dependencies>
<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.2.0" />
<!--...-->
</dependencies>
</info>
</ivy-module>
When I run Ivy, it fetches all dependencies for EHCache, even testing dependencies. Specifically, it tries to pull in Hibernate 3.5.1 (which, in the POM file, is listed as a "test" dependency).
How do I prevent Ivy from including test dependencies? I could list it as an excluded dependency, but I don't want to have to do this for every test dependency. I'm new to Ivy and used to the way Maven does things. I was reading about configurations but I don't understand how this aspect of Maven's "scope" maps to "configurations."
You need to define the configuration of the dependency like:
<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.2.0" conf="compile"/>
If you omit conf it is assumed, that you meant conf ="*", which will download all configurations for that dependency.
Here is a simple Example:
<configurations>
<conf name="test" visibility="public" />
<conf name="compile" visibility="public" />
</configurations>
<publications>
<artifact name="${project.name}" type="jar" conf="compile" ext="jar"/>
<artifact name="${project.name}-test" type="jar" conf="test" ext="jar"/>
</publications>
<dependencies>
<!-- COMPILE -->
<dependency org="log4j" name="log4j" rev="1.2.14" conf="compile->*"/>
<dependency org="apache" name="commons-net" rev="2.0" conf="compile->*"/>
<dependency org="itext" name="itext" rev="1.4.6" conf="compile->*"/>
<dependency org="jsch" name="jsch" rev="0.1.29" conf="test->*"/>
<!-- TEST -->
</dependencies>
In this example jsch will be included in the test and the compile configuration.
If you resolve this dependency later with conf ="compile" you will get all dependencies EXCEPT jsch.
If you resolve this dependency with conf ="test" you will get jsch only.
And if test would extend compile, you would get all jars.
<configurations>
<conf name="test" visibility="public" extends="compile" />
<conf name="compile" visibility="public" />
</configurations>