Prevent IvyDE from resolving specific build time dependencies - eclipse

Its maybe that I'm trying to misuse Ivy, but if I am then I definitely don't understand 'configurations'
I have a dependency I want to access only when running my build script under Jenkins. In my eclipse workspace I have no need for the dependency. Is it possible to achieve this?
For example if I wanted to pull ant-contrib in at build time I have tried setting up my configuration file as follows:
<configurations defaultconf="compile">
<conf name="compile" visibility="public" />
<conf name="build" visibility="public" extends="compile" />
</configurations>
<dependencies>
<dependency org="junit" name="junit" rev="4.8.1" conf="compile->default" />
<dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" conf="build->*" />
</dependencies>
With this example I always end up with ant contrib and ant on my build path in eclipse which isn't what I wanted. The resolve ant task allows me to resolve a specific configuration so I assumed that IvyDE would only resolve the default one. What am I missing?
Thanks,
Dan.

When adding the ivy file using IvyDE it is possible to select the configurations that should be resolved. This way only compile can be selected and only junit would be resolved.
It seems that to change this you need to remove and re-add the ivy dependency, I can't find any settings to change the configurations without doing that.

Related

Eclipse/Grails - Tests don't run - ClassNotFoundException [duplicate]

While running junit test in eclipse I am getting this Exception:
java.lang.NoClassDefFoundError: org/hamcrest/SelfDescribing
I've added junit.jar library file.
I've tried different versions of junit.jar: 4.4, 4.8, etc.
How do I fix this Exception?
Add hamcrest-all-X.X.jar to your classpath.
Latest version as of Feb 2015 is 1.3:
http://code.google.com/p/hamcrest/downloads/detail?name=hamcrest-all-1.3.jar&can=2&q=
According to the JUnit GitHub team website (https://github.com/junit-team/junit/wiki/Download-and-Install), junit.jar and hamcrest-core.jar are both needed in the classpath when using JUnit 4.11.
Here is the Maven dependency block for including junit and hamcrest.
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- Needed by junit -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
A few steps you have to follow:
Right click on the project.
Choose Build Path Then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
Works for me: IntelliJ IDEA 13.1.1, JUnit4, Java 6
I changed the file in project path: [PROJECT_NAME].iml
Replaced:
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
By:
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
So the final .iml file is:
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
P.S.: save the file and don't let to IntelliJ Idea reload it. Just once.
You need junit-dep.jar because the junit.jar has a copy of old Hamcrest classes.
Just in case there's anyone here using netbeans and has the same problem, all you have to do is
Right click on TestLibraries
Click on Add Library
Select JUnit and click add library
Repeat the process but this time click on Hamcrest and the click add library
This should solve the problem
This problem is because of your classpath miss hamcrest-core-1.3.jar. To resolve this add hamcrest-core-1.3.jar as you add junit-4.XX.jar into your classpath.
At first, I encounter this problem too, but after I refer to the official site and add hamcrest-core-1.3.jar into classpath with command line, it works properly finally.
javac -d ../../../../bin/ -cp ~/libs/junit-4.12.jar:/home/limxtop/projects/algorithms/bin MaxHeapTest.java
java -cp ../../../../bin/:/home/limxtop/libs/junit-4.12.jar:/home/limxtop/libs/hamcrest-core-1.3.jar org.junit.runner.JUnitCore com.limxtop.heap.MaxHeapTest
You need to add the hamcrest-core JAR to the classpath as described here: https://github.com/junit-team/junit4/wiki/Download-and-Install
As a general rule, always make sure hamcrest is before any other testing libraries on the classpath, as many such libraries include hamcrest classes and may therefore conflict with the hamcrest version you're using. This will resolve most problems of the type you're describing.
the simplest way of solving the problem to begin with is copying latest version of hamcrest-code.jar into your CLASSPATH that is the file you store other .jar files needed for compilation and running of your application.
that could be e.g.: C:/ant/lib
It sounds like a classpath issue, so there are a few different ways to go about it. Where does org/hamcret/SelfDescribing come from? Is that your class or in a different jar?
Try going to your project Build Path and on the Libraries tab, add a Library. You should be able to choose JUnit to your project. This is a little bit different than just having the JUnit jar file In your project.
In your Run Configuration for the JUnit test, check the Classpath. You could probably fix this by adding making sure your Classpath can see that SelfDescribing class there. The Run option in Eclipse has a different set of options for the JUnit options.
If this problem arise in a RCP project it can be because JUnit has been explicitly imported.
Check the editor for your plugin.xml under Dependencies tab, remove the org.junit from the Imported Packages and add org.junit to the Required Plug-ins.
The problem is when you set up eclipse to point to JRE instead of JDK. JRE has junit4.jar in the lib/ext folder, but not hamcrest.jar :) So the solution is to check installed JREs in Eclipse, remove the existing one and create a new one pointing to your JDK.
This happens when you run Ant via command line. The implicit user dependencies are added in the classpath at the end and take precedence over the project-added classpath. Run Ant with -nouserlib flag. The implicit dependencies would be excluded from the classpath.
There is a better answer to solve this problem.
add dependency
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
The hamcrest-core-1.3.jar available on maven repository is deprecated.
Download working hamcrest-core-1.3.jar from official Junit4 github link .
If you want to download from maven repository, use latest hamcrest-XX.jar.
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
I had the same problem, the solution is to add in build path/plugin the jar org.hamcrest.core_1xx, you can find it in eclipse/plugins.
A few steps you have to follow:
Right click on the project.
Choose Build Path & then from its menu choose Add Libraries.
Choose JUnit then click Next.
Choose JUnit4 then Finish.
This works for me...
"java.lang.SecurityException: class" org.hamcrest.Matchers "'s signer information does not match signer information of other classes in the same package"
Do it:
Right-click on your package
click on Build Path -> Configure Build Path
Click on the Libraries tab
Remove JUnit
Apply and close
Ready.
Try adding the jar files manually or try with force update with the latest hamcrest.jar

Ivy + eclipse runtime dependencies deployment

I have an eclipse project with IvyDE managed dependencies
My IvyDE is something like:
<ivy-module version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="R01"
module="myModule"
status="integration">
</info>
<configurations>
<conf name="compile" description="Used only at compile time; not deployed to the server" />
<conf name="runtime" extends="compile" description="Deployed to the server"/>
</configurations>
<dependencies>
<dependency org="com.sun.jersey" name="jersey-core" rev="1.9.1" conf="runtime"/>
<dependency org="javax.ws.rs" name="jsr311-api" rev="1.1.1" conf="compile"/>
</dependencies>
</ivy-module>
I have dependencies needed at compile-time and dependencies needed at runtime
I don't know if this is possible with apache IVY in eclipse (IvyDE) but I want to deploy to the server ONLY the RUNTIME-dependencies.
Now the only solution I've found is:
set IvyDE to resolve ALL (compile + runtime) dependencies and set the module classpath
add the [Ivy] library to the [DeploymentAssembly] at the project properties
This way all the dependencies (including the compile-time dependencies) are deployed to the server...
Is there any way to achieve this???
Thanks in advance
I answer my own question.
Finally I managed to get have TWO different ivy-managed classpath libraries, one used at compile-time and the other at run-time
The trick is include TWO ivyDE-managed dependencies:
One ivyDE managed dependency should be for COMPILE configuration and the other for RUNTIME configuration:
(repeat for the RUNTIME configuration)
Then it's only a matter of setting:
ivy dependency for COMPILE config should be a [Project Library]
ivy dependency for RUNTIME config should be at [Deployment Assembly]
That's all!

Have added Ivy management to Eclipse project, then what?

Have added Ivy management to one of my eclipse projects. Nothing happened after that.
I have a guide to add something to ivy.xml and ivysettings.xml, so what? How to create empty versions of these files? Where to put them?
I have created some by intuition, in the project root, then added to files what was told.
Nothing happened. Where are new libraries? How to force Ivy to do something?
Versions:
Apache IvyDE 2.2.0.beta1-201203282058-RELEASE
Eclipse Helios Service Release 2
Guides for ivy are for xuggler: http://www.xuggle.com/downloads
I have created ivy.xml by File New and added what was said without ellipsis. icysettings.xml are just the sample w/o ellipsis.
Yes ivy.xml should be in the root (for default configuration).
try this:
<ivy-module
version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"
xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.organisation" module="stackoverflow" revision="1.0.0" status="integration" >
</info>
<configurations>
<conf name="default" />
</configurations>
<dependencies>
<dependency org="xuggle" name="xuggle-xuggler" rev="5.2" />
</dependencies>
</ivy-module>
Create ivysettings.xml file in the root as well. This one is adapted to your need
<ivysettings> <
settings defaultResolver="default" />
<include url="${ivy.default.settings.dir}/ivysettings.xml" />
<resolvers>
<url m2compatible="true" name="xugglecode">
<ivy
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[organization]/[artifact]/[revision]/ivy-[revision].xml" />
<ivy
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[organization]/[artifact]/ivy-[revision].xml" />
<artifact
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[organisation]/[artifact]/[revision]/[artifact](-[revision]).[ext]" />
<artifact
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[organisation]/[artifact]/[artifact](-[revision]).[ext]" />
<artifact
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[organisation]/[artifact](-[revision]).[ext]" />
<artifact
pattern="http://xuggle.googlecode.com/svn/trunk/repo/share/java/[artifact](-[revision]).[ext]" />
<artifact
pattern="http://build.xuggle.com/view/Stable/job/red5_jdk6_stable/lastSuccessfulBuild/artifact/workingcopy/dist/[artifact].[ext]" />
</url>
<chain name="default" changingPattern=".*SNAPSHOT">
<resolver ref="xugglecode" />
</chain>
</resolvers>
</ivysettings>
Now when you add ivy management, in Main tab you should see Ivy File: ivy.xml as default.
now go to settings tab. Check the box of 'Enable project specific settings'.
in Ivy settings path, easier to choose the one you just created in your root project using 'Workspace button'. Navigate and choose.
Press ok. It will start resolving immediately.
I should tell you, that even though the file exists, I couldn't retrieve it. The ivy- console seems stuck. I'm receiving Status Code 403. I'm doing from work.
Maybe you have better luck resolving it. If not, consider this as a mini example of how to set up IvyDE.

Ivy fails to resolve a dependency, unable to find cause

While using ivy:retrieve, it fails to resolve the dependency that should be downloaded. The output looks like this:
Buildfile: C:\Users\Simon\workspace\apollo\build.xml
init:
resolve:
BUILD FAILED
C:\Users\Simon\workspace\apollo\build.xml:42: Problem: failed to create task or type antlib:org.apache.ivy.ant:retrieve
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.
No types or tasks have been defined in this namespace yet
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
-C:\Users\Simon\.ant\lib
-a directory added on the command line with the -lib argument
Total time: 348 milliseconds
The relevant section of the build.xml looks like so:
<target name="resolve" depends="init">
<ivy:retrieve pattern="${lib}/[artifact]-[revision].[ext]" sync="true" />
</target>
Here is also a list of what it should be downloading (from the build.xml)
<target name="doc" depends="build">
<javadoc sourcepath="${src}" classpathref="libraries" access="private" destdir="${doc}" windowtitle="Apollo">
<doclet name="org.jboss.apiviz.APIviz" pathref="libraries">
<param name="-sourceclasspath" value="${bin}" />
<param name="-author" />
<param name="-version" />
<param name="-use" />
<param name="-nopackagediagram" />
</doclet>
<doctitle><![CDATA[<h1>Apollo</h1>]]></doctitle>
<link href="http://download.oracle.com/javase/6/docs/api/" />
<link href="http://docs.jboss.org/netty/3.2/api/" />
<link href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/" />
<link href="http://www.junit.org/apidocs/" />
<link href="http://commons.apache.org/compress/apidocs/" />
<link href="http://jruby.org/apidocs/" />
</javadoc>
</target>
ANT cannot find the ivy jar. Needs to be downloaded, extracted, and the ivy-x.y.z.jar placed into one of the following locations:
$ANT_HOME/lib
$HOME/.ant/lib
Enabling ivy
Ivy is packaged as an antlib, so to enable it you need to do the following
1)
Declare the ivy namespace at the top of the build file
<project ..... xmlns:ivy="antlib:org.apache.ivy.ant">
2)
Include the ivy jar in one of the ant library directories
Your error message indictates some of the possible locations for antlibs:
This appears to be an antlib declaration.
Action: Check that the implementing library exists in one of:
-C:\Users\Simon\eclipse\plugins\org.apache.ant_1.8.2.v20120109-1030\lib
-C:\Users\Simon\.ant\lib
-a directory added on the command line with the -lib argument
Note:
The beauty of an antlib is that you don't need to perform the taskdef (It's optional if you want to place the ivy jar in a non-standard location)
How to bootstrap a build
Even though ivy is an ANT sub-project, for some inexplicable reason ivy is not packaged with ANT....
I normally include the following target in my build files to setup a new environment:
<target name="bootstrap" description="Used to install the ivy task jar">
<mkdir dir="${user.home}/.ant/lib"/>
<get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.2.0/ivy-2.2.0.jar"/>
</target>
It downloads the ivy jar from Maven Central.
Since all other ANT tasks can subsequently be downloaded using ivy, few people object to this little piece of ugliness at the top of the build file.
If you can't put the ivy libs in the classpath for ant you will need to define it yourself:
<path id="ivy.lib.path">
<fileset dir="path/to/dir/with/ivy/jar" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
This bit is missing from the getting started tutorial, but listed here: http://ant.apache.org/ivy/history/2.2.0/ant.html
When you Run Ant task, in the classpath ensure that ivy.jar is there. In the eclipse -> Run As-> Ant Build -> Edit configuration -> Classpath tab. Even though Eclipse would have the ivy.jar in the ANT Home, for some reason it's not called.
I had a similar problem on MacOSX (10.11.6 El Capitan). I installed ant and Ivy with the Brew package manager.
One additional way is to define it manually using the -lib option, e.g.:
ant clean compile -lib /usr/local/Cellar/ivy/2.4.0/libexec/ivy-2.4.0.jar
Even after adding ivy jar to the ant lib, it was not being picked up. Selecting the ANT_HOME again in Preferences->Ant->Runtime will cause the lib dir to be refreshed, and any libraries you have added there to be taken up.

Eclipse Ivy plugin says jruby has an unresolved dependency, but jruby 1.6.6 doesn't have any

I'm getting this error when I try to add jruby as a dependency using the ivy Eclipse plugin:
Impossible to resolve dependencies of com.restphone#;working#James-Moores-iMac.local
unresolved dependency: org.jruby.extras#bytelist;1.0.8: not found
This is in my ivy.xml:
<dependency org="org.jruby"
name="jruby-complete"
rev="1.6.6" />
And this is in ivysettings.xml:
<ivysettings>
<settings defaultResolver="chain"/>
<resolvers>
<chain name="chain">
<ibiblio name="codehaus" m2compatible="true" root="http://repository.codehaus.org/"/>
</chain>
</resolvers>
</ivysettings>
But according to the jruby mailing list, jruby has NO dependencies for runtime, compile or
test scope.
Do I need to give the ivy plugin more information somewhere?
In my opinion it's always a good idea to specify a configuration mapping for your dependencies.
The following ivy file worked fine for me. As described, only the ruby jar was downloaded.
<ivy-module version="2.0">
<info organisation="org.demo" module="demo"/>
<configurations>
<conf name="compile"/>
<conf name="runtime" extends="compile"/>
<conf name="test" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="org.jruby" name="jruby-complete" rev="1.6.6" conf="compile->default"/>
</dependencies>
</ivy-module>
Here I have mapped my local "compile" configuration to the default remote configuration. (In a Maven module, the default ivy configuration translates to the "compile" scope).
I dug into the remote POM file:
<properties>
<jar.scope>provided</jar.scope>
..
..
<dependency>
<groupId>org.jruby.joni</groupId>
<artifactId>joni</artifactId>
<scope>${jar.scope}</scope>
</dependency>
<dependency>
<groupId>org.jruby.extras</groupId>
<artifactId>jnr-netdb</artifactId>
<scope>${jar.scope}</scope>
</dependency>
...
All the extra depedencies have been declared in the "provided" Maven scope.
Couple of issues:
1)
In Maven the provided scope is used for jars which are required for compiling that module. They do not need to be packaged because they are part of the target runtime environment. Similarily such dependencies are not needed as transitive dependencies for your module and hence don't need to downloaded.
2)
All the jars are all located in the Maven Central repository. The following settings file would retrieve everything, if you chose to omit the ivy configuration mapping
<ivysettings>
<property name="ivy.checksums" value=""/>
<settings defaultResolver="chain"/>
<resolvers>
<chain name="chain">
<ibiblio name="central" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
3)
The following error is caused by a junk checksum. My provided settings file disables this check... something you are advised not to do on a remote repository
[ivy:resolve] :::: WARNINGS
[ivy:resolve] problem while downloading module descriptor: http://repo1.maven.org/maven2/org/jruby/extras/bytelist/1.0.8/bytelist-1.0.8.pom: invalid sha1: expected=e40ee094403473e43f71e21cf9cbf71f08d2098b computed=a9627bc7e42f886e290985367040794adb676320 (977ms)
[ivy:resolve] module not found: org.jruby.extras#bytelist;1.0.8
Although the JRuby docs may not state a required dependency, it looks as though the repository that you are using does...
You've asked for 'jruby-complete' and if you go and look at this POM you will see its specifying the jruby extras.
One option is to select a different POM file as the basis of your dependency, but a quick fix is to add the attribute transitive="false" to your dependency.
<dependency org="org.jruby"
name="jruby-complete"
transitive="false"
rev="1.6.6" />