Apache IVY Unable to resolve dependencies for MAVEN Projects - netbeans

I have a setup of Apache Ivy(Version 2.4.0) and Netbeans IDE(8.0.2). I have not been able to resolve dependencies for full blown maven projects(For example:org.glassfish.jersey). Apache Ivy successfully resolves dependencies for more specific modules like (org.glassfish.jersey.core).
Non working Example:
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
Working Examples:
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
<dependency org="org.glassfish.jersey.core" name="jersey-server" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
<dependency org="org.glassfish.jersey.core" name="jersey-client" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
<dependency org="org.glassfish.jersey.core" name="jersey-common" rev="2.13" conf="JerseyCore-2.13->default,optional"/>
ivy.xml
<ivy-module version="2.0">
<info organisation="org.sonatype.nexus.examples" module="simple-project" revision="1.0.0-SNAPSHOT"/>
<configurations>
<conf name="solrj" description="Jars from the SOLRJ Library Collection"/>
</configurations>
<dependencies>
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
</dependencies>
ivysettings.xml
<ivysettings>
<settings defaultResolver="ibiblio"/>
<resolvers>
<ibiblio name="ibiblio" m2compatible="true"/>
</resolvers>
build.xml(Just the IVY Part).
<!-- Resolve all the dependencies that we declared in the build.xml file.
Resolving means that ivy will download the jar file from the MAVEN 2 Repository
and put them under the directory that you specify in the build.xml file.
In my case this is where all the jar files will be downloaded "C:\Users\ajalgaon\Accurev\solrj\lib" -->
<target name="init">
<ivy:settings file="ivysettings.xml" />
<ivy:resolve/>
<ivy:report todir="prebuilt/ivy-report" graph="false"/>
<ivy:retrieve conf="solrj" pattern="prebuilt/jars/solrj-lib/[artifact].[ext]"/>
</target>
Apache IVY Successfully resolves dependencies for the solr-solrj module. But it does not resolve dependency for "org.glassfish.jersey". Apache IVY Does not resolve dependencies for anything that has the attribute name="project" in the ivy.xml file. Kindly let me know if I need to post more information here. Thanks a lot in advance.

Cannot reproduce your issue.
Example
├── build.xml
├── ivy.xml
└── target
├── ivy-reports
│   ├── ivy-report.css
│   └── org.sonatype.nexus.examples-simple-project-solrj.html
└── jars
├── commons-io.jar
├── httpclient.jar
├── httpcore.jar
├── httpmime.jar
├── noggit.jar
├── slf4j-api.jar
├── solr-solrj.jar
├── stax2-api.jar
├── woodstox-core-asl.jar
└── zookeeper.jar
ivy.xml
<ivy-module version="2.0">
<info organisation="org.sonatype.nexus.examples" module="simple-project" revision="1.0.0-SNAPSHOT"/>
<configurations>
<conf name="solrj" description="Jars from the SOLRJ Library Collection"/>
</configurations>
<dependencies>
<dependency org="org.glassfish.jersey" name="project" rev="2.13" conf="solrj->*"/>
<dependency org="org.apache.solr" name="solr-solrj" rev="5.0.0" conf="solrj->default"/>
</dependencies>
</ivy-module>
build.xml
<project name="demo" default="resolve" xmlns:ivy="antlib:org.apache.ivy.ant">
<property name="build.dir" location="target"/>
<available classname="org.apache.ivy.Main" property="ivy.installed"/>
<target name="resolve" depends="install-ivy" description="Use ivy to resolve classpaths">
<ivy:resolve/>
<ivy:report todir='${build.dir}/ivy-reports' graph='false' xml='false'/>
<ivy:retrieve conf="solrj" pattern="${build.dir}/jars/[artifact].[ext]"/>
</target>
<target name="install-ivy" description="Install ivy" unless="ivy.installed">
<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.4.0/ivy-2.4.0.jar"/>
<fail message="Ivy has been installed. Run the build again"/>
</target>
<target name="clean" description="Cleanup build files">
<delete dir="${build.dir}"/>
</target>
<target name="clean-all" depends="clean" description="Additionally purge ivy cache">
<ivy:cleancache/>
</target>
</project>

Related

Phing - imported build file does not execute

New to phing, I feel dumb but when I import one build file into another. The imported build file does not execute. I must have something wrong (note that $ phing --buildfile imported.xml runs fine).
I have tried:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
</target>
<import file="import.xml"/>
</project>
AND
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
<import file="import.xml"/>
</target>
</project>
Nevermind, I see that you have to make a inside the default target.
so now:
<?xml version="1.0" encoding="UTF-8"?>
<project name="myproject" default="project" basedir="." description="Set up project">
<target name="project">
<echo msg="Deploy" />
<phingcall target="importedTarget" />
</target>
<import file="import.xml"/>
</project>
I think that the problem is with the "namespaces". I explain you my case, that could be yours.
I have a build.xml file that imports this structure:
.
├── bin
│   ├── phing
│   │   ├── qgpl
│   │   │   ├── console.xml
│   │   │   └── folder.xml
│   │   └── skel.xml
importing these tasks at the bottom of build.xml
<import file="${tasks.dir}/phing/skel.xml" optional="false" />
<import file="${tasks.dir}/phing/qgpl/console.xml" optional="false" />
<import file="${tasks.dir}/phing/qgpl/folder.xml" optional="false" />
If the file bin/phing/qgpl/console.xml is defined with:
<project name="qgpl.console" basedir="${build.dir}" >
I get the targets duplicated:
phing -l
Buildfile: build.xml
[property] Loading etc/config.ini
[property] Loading etc/local-config.ini
[property] Loading etc/after-local-config.ini
Default target:
-------------------------------------------------------------------------------
build Build the application
Main targets:
-------------------------------------------------------------------------------
base64Encode Convertim a Base64 una cadena preguntada
[...]
qgpl_console.base64Encode Convertim a Base64 una cadena preguntada
But if there is only one base64Encode target in the project, I must to execute it with
phing base64Encode
because
phing qgpl_console.base64Encode
do nothing, no errors but nothing executed.
I fix it removing the project name keyword in the imported files
<project basedir="${build.dir}" >
And adding the "namespace" in each target
<target name="qgpl.console.base64Encode" description="Convertim a Base64 una cadena preguntada" >
<input propertyname="stringPlain">Input string to convert to Base64</input>
<qgpl.base64Encode string="${stringPlain}" returnProperty="string64" />
<echo>${string64}</echo>
</target>
I was searching in the documentation, but I don't found other way to do it.

Ivy test configuration in eclipse

I have an ivy dependency management to work both under eclipse and with ant.
How should I configure the test dependencies to be available for eclipse?
my current configuration is:
<configurations>
...
<conf name="test" visibility="public"/>
</configurations>
<dependencies>
...
<dependency org="org.testng" name="testng" rev="6.7" conf="test->provided" transitive="false"/>
</dependencies>
With that configuration TestNG is not "retrieved". I'm using IvyDE, and 'Select every configuration' is set.

Ivy resolves jersey-servlet from Ant but not IvyDE

I'm trying to build a restful server using Apache Jersey. I'm developing in Eclipse Indigo and using Ivy for dependency management with this ivy.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!--=========================================================================-->
<!--
-->
<!--=========================================================================-->
<ivy-module version="2.2">
<info organisation="com.mypackage" module="mymodule"/>
<dependencies>
<dependency org="com.sun.jersey" name="jersey-servlet" rev="1.12"/>
</dependencies>
</ivy-module>
This resolves fine calling ivy from ant, but from IvyDE I get this error
Some projects fail to be resolved
Impossible to resolve dependencies of com.mypackage#mymodule;working#Samsung-Windows
unresolved dependency: org.jboss.weld#weld-spi;1.1.4.Final: not found
unresolved dependency: javax.annotation#jsr250-api;${jsr250.api.version}: not found
unresolved dependency: org.jboss.weld#weld-api;1.1.4.Final: not found
unresolved dependency: javax.inject#javax.inject;${atinject.api.version}: not found
unresolved dependency: org.jboss.spec.javax.interceptor#jboss-interceptors-api_1.1_spec;${interceptor.api.version}: not found
To me the ${atinject.api.version} looks like it is somehow not resolving variables correctly somewhere.
My understanding of Ivy is very superficial, so I don't have any good ideas.
Both IvyDE and ant are using the same ivysettings.xml file (at least, I believe they are).
<?xml version="1.0" encoding="UTF-8"?>
<!--=========================================================================-->
<!--=========================================================================-->
<ivysettings>
<settings defaultResolver="ibiblio"/>
<resolvers>
<ibiblio name="ibiblio" m2compatible="true"/>
<ibiblio name="maven2" m2compatible="true"/>
<ibiblio name="java-net-maven1" root="http://download.java.net/maven/1" pattern="${java.net.maven.pattern}" m2compatible="false"/>
<ibiblio name="java-net-maven2" root="http://download.java.net/maven/2/" m2compatible="true"/>
</resolvers>
</ivysettings>
Any direction would be great.
Thanks a lot in advance.
Edit: Adding portion of Build.xml
I'm using apache-ivy-2.2.0 although the output claims:
[ivy:configure] :: Apache Ivy 2.3.0-rc1 - 20120416000235 :: http://ant.apache.org/ivy/ ::
This is the build.xml:
<?xml version="1.0"?>
<project name="IvyTest" default="ivy.retrieve" xmlns:ivy="antlib:org.apache.ivy.ant">
<description>
IvyTest
</description>
<!--=====================================================================-->
<!-- Properties -->
<!--=====================================================================-->
<!-- General properties. -->
<property name="bin" location="bin" />
<property name="lib" location="lib" />
<property name="lib.ivy" location="${lib}/ivy-managed" />
<property name="ivy.version" value="2.2.0" />
<property name="ivy.home" location="${bin}/apache-ivy-${ivy.version}" />
<available property="ivy.installed" file="${ivy.home}/ivy-${ivy.version}.jar" />
<property name="ant.build.javac.source" value="1.7" />
<property name="ant.build.javac.target" value="1.7" />
<!--=====================================================================-->
<!-- Targets: Ivy -->
<!--=====================================================================-->
<!--============================ ivy.download ===========================-->
<target name="ivy.download" unless="ivy.installed">
<mkdir dir="${ivy.home}"/>
<get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.version}/ivy-${ivy.version}.jar" dest="${ivy.home}/ivy-${ivy.version}.jar" usetimestamp="true"/>
</target>
<!--============================ ivy.init ===============================-->
<target name="ivy.init" depends="ivy.download">
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpath="${ivy.home}/ivy-${ivy.version}.jar"/>
</target>
<!--============================ ivy.resolve ============================-->
<target name="ivy.resolve" description="Resolve dependencies with Ivy" depends="ivy.configure">
<ivy:resolve />
</target>
<!--============================ ivy.retrieve ===========================-->
<target name="ivy.retrieve" description="Retrieve dependencies with Ivy" depends="ivy.configure">
<ivy:retrieve log="verbose" pattern="${lib.ivy}/[artifact]-[revision].[ext]" type="jar,bundle" sync="true"/>
</target>
<!--============================ ivy.configure ==========================-->
<target name="ivy.configure" description="Configure Ivy settings file" depends="ivy.init">
<ivy:configure file="ivysettings.xml"/>
</target>
<!--============================ ivy.clean ==============================-->
<target name="ivy.clean" description="Cleans the Ivy cache" depends="ivy.init">
<ivy:cleancache />
</target>
</project>
By default ivy will download dependencies from Maven Central, so unless you're using your own Maven repository manager you won't need an ivy settings file.
Having said that it's good practice to declare one and the following works fine for me:
<ivysettings>
<settings defaultResolver="central"/>
<resolvers>
<ibiblio name="central" m2compatible="true"/>
</resolvers>
</ivysettings>
Notice it's a lot simpler than your example. The old java.net repositories are not really used anymore, most (if not all) of their content has been migrated to Maven Central.
As an update to your original question:
I also had the situation that I could resolve on the console using ant resolve but IvyDe (under Eclipse 4.2) was giving me the error "Impossible to resolve dependencies [...]"
Lead through this post I managed to edit IvyDE's settings (Workspace Preferences -> Ivy -> Settings) and add an ivysettings.properties file with this content:
ivy.home=${user.home}/.ant
ivy.jar.dir=${ivy.home}/lib
ivy.jar.file=${ivy.jar.dir}/ivy.jar
From now on everything worked fine.

How to attach sources to SBT managed dependencies in Scala IDE?

I'm using Scala IDE 2.0.1 and SBT 0.11.2 to start with Akka 2.0.1. My build.sbt looks like this:
name := "akka"
version := "0.1"
scalaVersion := "2.9.2"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0.1"
As you can see, there's nothing spectacular.
Now how can I tell Eclipse to use the artifact with the sources classifier for the akka-actor library?
In SBT, I can use update-classifiers to download sources and Javadocs to the Ivy repository, but even if I do this before running the eclipse command from the sbteclipse plugin then Eclipse still does not know the sources. Of course, I could do this manually, but this doesn't scale well for more libraries.
I have also tried to use the IvyDE plugin with the deliver-local command. While this integrates the dependency management, it doesn't seem to help with the sources.
Any clues?
Edit: This is the ivy.xml generated from deliver-local:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="default" module="akka_2.9.2" revision="0.1" status="release" publication="20120506225613">
<description>
akka
</description>
</info>
<configurations>
<conf name="compile" visibility="public" description=""/>
<conf name="runtime" visibility="public" description="" extends="compile"/>
<conf name="test" visibility="public" description="" extends="runtime"/>
<conf name="provided" visibility="public" description=""/>
<conf name="optional" visibility="public" description=""/>
<conf name="sources" visibility="public" description=""/>
<conf name="docs" visibility="public" description=""/>
<conf name="pom" visibility="public" description=""/>
</configurations>
<publications>
<artifact name="akka_2.9.2" type="pom" ext="pom" conf="pom"/>
<artifact name="akka_2.9.2" type="jar" ext="jar" conf="compile"/>
<artifact name="akka_2.9.2" type="src" ext="jar" conf="sources" e:classifier="sources"/>
<artifact name="akka_2.9.2" type="doc" ext="jar" conf="docs" e:classifier="javadoc"/>
</publications>
<dependencies>
<dependency org="org.scala-lang" name="scala-library" rev="2.9.2" conf="compile->default(compile)"/>
<dependency org="com.typesafe.akka" name="akka-actor" rev="2.0.1" conf="compile->default(compile)"/>
<exclude org="org.scala-lang" module="scala-library" artifact="*" type="jar" ext="*" matcher="exact"/>
<exclude org="org.scala-lang" module="scala-compiler" artifact="*" type="jar" ext="*" matcher="exact"/>
<override org="org.scala-lang" module="scala-library" matcher="exact" rev="2.9.2"/>
<override org="org.scala-lang" module="scala-compiler" matcher="exact" rev="2.9.2"/>
</dependencies>
</ivy-module>
I'm new to Ivy, so this doesn't tell me much. I just figure that it mentions sources and javadocs, but somehow the IvyDE doesn't pick it up.
You can put
EclipseKeys.withSource := true
to your build.sbt, which lets sbteclipse download all sources and makes them accessible within Eclipse. Note, this will download all sources from all configured dependencies. I have no idea how to tell sbt to download only the sources for single dependencies.
Finally I found a solution to let sbt download the sources and tell Eclipse where to find them.
Add in build.sbt:
EclipseKeys.withSource := true
Then run:
rm -rf ~/.ivy2/cache/
sbt update-classifiers
sbt eclipse
The weird part is that if you already downloaded the dependencies in ivy, you have them in cache and you won't be able to download the sources for them.
I managed to get this working finally.
I had to use an external ivy settings file:
<ivysettings>
<properties environment="env" />
<settings defaultResolver="play" defaultResolveMode="dynamic" />
<caches defaultCacheDir="${env.PLAY_HOME}/repository/cache" />
<resolvers>
<chain name="play">
<ibiblio name="typesafe-releases" m2compatible="true" root="http://repo.typesafe.com/typesafe/releases" />
<ibiblio name="sonatype-oss-releases" m2compatible="true" root="http://oss.sonatype.org/content/repositories/releases" />
<filesystem name="local-filesystem">
<ivy pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/ivys/ivy.xml" />
<artifact pattern="${env.PLAY_HOME}/repository/local/[organization]/[module]/[revision]/[type]s/[module](-[classifier]).[ext]" />
</filesystem>
<ibiblio name="central-uk" m2compatible="true" root="http://uk.maven.org/maven2" />
<ibiblio name="typesafe-snapshots" m2compatible="true" root="http://repo.typesafe.com/typesafe/snapshots" />
<ibiblio name="sonatype-oss-snapshots" m2compatible="true" root="http://oss.sonatype.org/content/repositories/snapshots" />
</chain>
</resolvers>
</ivysettings>
And add:
externalIvySettings(baseDirectory(_ / "ivysettings.xml"))
to my Build.scala.
The order of the resolvers in the chain proved to be important, because if Ivy finds a jar but no sources it won't check the other resolvers for sources/javadoc. The repository in the local Play install doesn't have sources or javadoc in.
This gets me source attachments for most of the jars in my dependencies when IvyDE resolves in Eclipse.
I find that it's easier to give IvyDE and sbt different ivy cache directories. Yes, it takes more space, but sbt by default doesn't download sources. And once sbt has loaded the cache without sources, IvyDE won't add them. You can tell sbt to fetch them, but for me it's easier just to use more disk space and use two different caches.
I do this by leaving sbt at the default, and setting IvyDE to use this file in Preferences > Ivy > Settings tab > Ivy settings file:
<ivysettings>
<settings defaultResolver="nexus" />
<property
name="nexus-public"
value="http://localhost:8081/nexus/content/groups/public" />
<resolvers>
<ibiblio
name="nexus"
m2compatible="true"
root="${nexus-public}" />
</resolvers>
<caches defaultCacheDir="${user.home}/.ivy2eclipse" />
</ivysettings>
That points to my local nexus server, so'll you'll need to modify it for your environment.
Well, I have given up on this and returned to NetBeans 7.1.2 + Scala plugin + Maven. This combination is much better integrated and works out of the box without tinkering.

Ivy downloading more jars than expected

Summary:
Ivy is downloading more jars than I expect and I don't know why.
Details:
I'm converting my project from using Maven Ant Tasks for dependency management to Ivy.
So far, I have done the following:
Installed IvyDE into my Eclipse (Helios)
Created an ivy.xml
Since I was previously successfully using Maven Ant Tasks I copied my
dendencies from my build.xml to the ivy.xml. I made sure to change
the dependency declarations to use the Ivy format (org, name, rev).
Added the IvyDE classpath container to my Eclipse project.
Now when I run Ivy > Resolve in Eclipse I can see that 279 jars are downloaded to ".ivy2\cache". This is way more than the 65 jars the Maven Ant Tasks were previously downloading.
Why is Ivy bringing down so many more jars? I understand that Ivy is also bringing down source and some javadoc jars. That explains some of the extra jars but I figure at most Ivy should download 195 jars (65*3) not 279.
What am I missing or doing wrong? I'd appreciate any feedback and suggestions.
Here's the contents of my ivy.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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="org.robbins"
module="FlashCardsWeb"
status="integration">
</info>
<dependencies>
<dependency org="org.apache.struts" name="struts2-core" rev="2.2.3"/>
<dependency org="org.apache.struts" name="struts2-spring-plugin" rev="2.2.3">
<exclude org="org.springframework" name="spring-web" />
<exclude org="org.springframework" name="spring-beans" />
<exclude org="org.springframework" name="spring-context" />
<exclude org="org.springframework" name="spring-core" />
</dependency>
<dependency org="org.springframework" name="spring-web" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-beans" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-context" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-core" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-jdbc" rev="3.0.5.RELEASE"/>
<dependency org="org.springframework" name="spring-orm" rev="3.0.5.RELEASE"/>
<dependency org="org.apache.struts" name="struts2-tiles-plugin" rev="2.2.1.1"/>
<dependency org="com.jgeppert.struts2.jquery" name="struts2-jquery-plugin" rev="3.0.1"/>
<dependency org="com.jgeppert.struts2.jquery" name="struts2-jquery-richtext-plugin" rev="3.0.1"/>
<dependency org="org.hibernate" name="hibernate-core" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-c3p0" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-entitymanager" rev="3.6.2.Final"/>
<dependency org="org.hibernate" name="hibernate-tools" rev="3.2.4.GA"/>
<dependency org="c3p0" name="c3p0" rev="0.9.1"/>
<dependency org="org.slf4j" name="slf4j-simple" rev="1.6.1"/>
<dependency org="commons-logging" name="commons-logging" rev="1.0.4"/>
<dependency org="mysql" name="mysql-connector-java" rev="5.1.15"/>
<dependency org="junit" name="junit" rev="4.8.1"/>
<dependency org="log4j" name="log4j" rev="1.2.14"/>
<dependency org="org.openid4java" name="openid4java-nodeps" rev="0.9.6" />
<dependency org="org.apache.httpcomponents" name="httpclient" rev="4.0" />
<dependency org="net.sourceforge.nekohtml" name="nekohtml" rev="1.9.10" />
</dependencies>
I had a similar issue and found this mail message helped.
The problem is that if you don't specify any conf, Ivy assumes you want all
the configurations of spring, which includes the optional conf. Try that
instead:
<dependency org="org.springframework" name="spring" rev="2.0.3"
conf="*->default"/>
http://mail-archives.apache.org/mod_mbox/ant-ivy-user/200703.mbox/%3C635a05060703310946q2f50880aqe07219c9e3026b83#mail.gmail.com%3E