I am new to Ivy and am a chronic ant user, so repositories are still sort of new to me.
I have a Spring 4 project and I'm attempting to build my data access stuff using Hibernate. I have the following ivy.mxl file being imported into my build.
<ivy-module version="2.0">
<info organisation="apache" module="data"/>
<dependencies>
<dependency org="org.eclipse.persistence" name="org.eclipse.persistence.core" rev="2.5.2-M1" />
<dependency org="org.eclipse.persistence" name="org.eclipse.persistence.jpa" rev="2.5.2-M1" />
<dependency org="com.ibm.websphere" name="com.springsource.com.ibm.websphere.uow" rev="6.0.2.17" />
<dependency org="org.springframework" name="spring-beans" rev="4.0.3.RELEASE" />
<dependency org="org.springframework" name="spring-context" rev="4.0.3.RELEASE" />
<dependency org="org.springframework" name="spring-orm" rev="4.0.3.RELEASE" />
<dependency org="org.springframework" name="spring-tx" rev="4.0.3.RELEASE" />
</dependencies>
</ivy-module>
I added the uow line as a result of this problem. When I build, I get the following message:
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: UNRESOLVED DEPENDENCIES ::
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:resolve] :: com.ibm.websphere#uow;6.0.2.17: not found
[ivy:resolve] ::::::::::::::::::::::::::::::::::::::::::::::
I google for this error and found nothing.
I found the library here: http://ebr.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.ibm.websphere.uow&version=6.0.2.17 and added the following to my ivysettings.xml file as a result of the FAQ from this link:
<url name="com.springsource.repository.bundles.release">
<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.bundles.external">
<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
And then added to my chain:
<resolver ref="com.springsource.repository.bundles.release"/>
<resolver ref="com.springsource.repository.bundles.external"/>
None of this has made any impact to my error. Any ideas?
Based on what I found here: Find hidden dependencies in Ivy I added transitive="false" to my dependency and it quit bringing it in.
Using this dependency statement I was able to resolve the problem.
<dependency org="org.springframework" name="spring-tx" rev="3.2.9.RELEASE"
transitive="false" conf="compile->default;runtime->default;"/>
It is located in the Redhat GA repo.
I added the repo to the resolvers in ivysettings.xml.
<resolvers>
<chain name="chained" returnFirst="true">
<ibiblio name="redhat" root="https://maven.repository.redhat.com/ga/" m2compatible="true"/>
</chain>
</resolvers>
I use the search facilities at http://mvnrepository.com/ . This lists where a library/artefact can be found.
Related
My dependencies.xml contains a lot of packages required for my web application to run
Following are a few notable fragments
<configurations>
<conf name="test" visibility="public" extends="compile" />
<conf name="compile" visibility="public" extends="runtime" />
<conf name="runtime" visibility="public" />
<conf name="provided" visibility="public" />
<conf name="junit" visibility="public" extends="test" />
</configurations>
<publications>
<artifact name="${project.name}" type="jar" ext="jar" conf="compile" />
<artifact name="${project.name}" type="zip" ext="zip" conf="compile"/>
</publications>
<dependencies>
<dependency org="org.hibernate" name="hibernate-core" rev="5.1.3.Final" transitive="false" conf="runtime->*"/>
<dependency org="org.hibernate" name="hibernate-ehcache" rev="5.1.3.Final" transitive="false" conf="runtime->*"/>
<dependency org="org.hibernate.common" name="hibernate-commons-annotations" rev="5.0.1.Final" transitive="false" conf="runtime->*"/>
<dependency org="org.hibernate.javax.persistence" name="hibernate-jpa-2.1-api" rev="1.0.0.Final" transitive="false" conf="runtime->*"/>
<dependency org="org.javassist" name="javassist" rev="3.21.0-GA" transitive="false" conf="runtime->*"/>
<dependency org="org.jboss.logging" name="jboss-logging" rev="3.3.0.Final" transitive="false" conf="runtime->*"/>
<dependency org="javax.transaction" name="jta" rev="1.1" transitive="false" conf="runtime->*"/>
<dependency org="net.sf.ehcache" name="ehcache-core" rev="2.6.11" transitive="false" conf="runtime->*"/>
<dependency org="antlr" name="antlr" rev="2.7.7" transitive="false" conf="runtime->*"/>
<dependency org="org.antlr" name="antlr4-runtime" rev="4.5.2-1" transitive="false" conf="runtime->*"/>
</dependencies>
I have package JTA from javax.transaction that is required for the application to run under Tomcat and forbidden for the application to run under WebSphere.
I need to know how to make two different WAR files depending on the target platform. I don't exactly know how to use configurations, if that is the way.
Ant will do an ivy-retrieve for configuration runtime and build a WAR archive using the jars downloaded from Artifactory.
I could exclude thos jar(s) manually by doing a delete after Ivy has resolved the artifacts, but hey, we are cool developers and we like to do the things the cleaner way.
How would you suggest me to do an ivy-retrieve that targets Tomcat including JTA an another that targets Websphere excluding it?
build.xml : Building war files
The following fragment builds two war files:
../demo.war
../demo-websphere.war
The magic is that the tomcat retrieve task includes two configurations:
<ivy:retrieve pattern="${lib.dir}/tomcat/[artifact].[ext]" conf="runtime,tomcat_only"/>
<war destfile="${dist.dir}/demo.war" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<lib dir="${lib.dir}/tomcat"/>
</war>
<ivy:retrieve pattern="${lib.dir}/websphere/[artifact].[ext]" conf="runtime"/>
<war destfile="${dist.dir}/demo-websphere.war" webxml="${resources.dir}/web.xml">
<fileset dir="${resources.dir}" excludes="web.xml"/>
<lib dir="${lib.dir}/websphere"/>
</war>
build.xml : Publishing
The following answer contains more details on publishing multiple module artifacts to a Maven repository
how to publish 3rdparty artifacts with ivy and nexus
So we need a target to generate the POM file:
<target name="prepare" description="Generate POM">
<!-- Optional: Intermediate file containing resolved version numbers -->
<ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="release"/>
<!-- Generate the Maven POM -->
<ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/demo.pom"/>
</target>
And a second target that publish the built files:
<target name="publish" depends="init,prepare" description="Upload to Nexus">
<ivy:publish resolver="nexus-deploy" pubrevision="${publish.revision}" overwrite="true" publishivy="false" >
<artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
</ivy:publish>
</target>
Take careful notice of the optional "classifier" attribute and note how the ivy file is structured next
ivy.xml
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
<info organisation="com.myspotontheweb" module="demo"/>
<configurations>
<conf name="master"/>
<conf name="default" extends="master,runtime"/>
<conf name="compile"/>
<conf name="provided"/>
<conf name="runtime" extends="compile"/>
<conf name="test" extends="runtime"/>
<conf name="tomcat_only" description="A special configuration for special tomcat only dependencies"/>
</configurations>
<publications>
<artifact name="demo" type="war" conf="master"/>
<artifact name="demo" type="pom" conf="master"/>
<artifact name="demo" type="war" conf="master" e:classifier="websphere"/>
</publications>
<dependencies>
<!-- Compile dependencies -->
<dependency org="org.hibernate" name="hibernate-core" rev="5.1.3.Final" conf="compile->default"/>
<dependency org="org.api" name="slf4j-api" rev="1.7.22" conf="compile->default"/>
<!-- Runtime dependencies -->
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.22" conf="runtime->default"/>
<!-- Tomcat dependencies -->
<dependency org="javax.transaction" name="jta" rev="1.1" conf="tomcat_only->master"/>
</dependencies>
</ivy-module>
Few things going on here.
1)
Make configuration mappings work for you
config1->default # Remote artifact plus transitive dependencies
config2->master # Remote artifact only (Same as setting transitive=false)
2)
The "extends" attribute is a set operation, meaning a compile dependency is automatically included as a runtime configuration.
An example is the SLF4J libary. The slf4j-api jar is required when compile code, where as the slf4j-log4j12 jar contained bindings and dependencies on log4j, a runtime (and changeable) dependency.
3)
The "master" configuration in your module is special and by convention in Maven world corresponds to the files published by this module.
4)
The "classifier" attribute is an example of a extra attribute in ivy.
At our company, we are migrating our old ivy repository to Nexus.
After uploading our own artifacts to Nexus, I tried downloading a few projects' dependencies to test the setup, but I'm failing with spring-web. Let me explain how.
Here is the ivy-settings.xml file pointing only to our local Nexus installation
<?xml version="1.0" encoding="ISO-8859-1"?>
<ivysettings>
<settings defaultResolver="default" />
<resolvers>
<ibiblio name="nexus" m2compatible="true" root="http://nexus.local/nexus/content/repositories/central/" />
<ibiblio name="our-nexus" m2compatible="true" root="http://nexus/nexus/content/repositories/repo" />
<chain name="default" returnFirst="true">
<resolver ref="our-nexus" />
<resolver ref="nexus" />
</chain>
</resolvers>
</ivysettings>
In one of our projects we use Spring Web, but not all of its dependencies, so I declared
<dependency org="org.springframework" name="spring-web" rev="3.0.5.RELEASE" transitive="false" />
This worked fine when using Ivy repository. However today I can't perform an <ivy:retrieve> task because it can't find com.caucho#hessian#3.2.1
<ivy:report> task says that such version of hessian is required by spring-web 3.2.11.RELEASE
But I have declared transitive="false"!!!
Why isn't it working? What am I missing/messing?
Should work. Personally I prefer configuration mappings. Try the following instead:
<dependency org="org.springframework" name="spring-web" rev="3.0.5.RELEASE" conf="default->master" />
For more details see:
How can I include the Ivy dependency and none of its dependencies?
I'm using json-schema-validator and guava in the same project. When I try to update either one I get a conflict for findbugs, so one lib is left out.
The working versions are:
json-schema-validator 2.0.0
guava 13.0.1
Both rely on findbugs 1.3.9
The version I'd like to use:
json-schema-validator 2.2.1
guava 16.0.1
Here json-schema-validator needs findbugs (jsr305) 2.0.1 and guava needs findbugs 1.3.9. Is there any way around this problem? With that I mean that I can use json-schema-validator version 2.2.1 and guava 16.0.1 in my project.
Sample files:
build.xml
<project name="example" default="download"
xmlns:ivy="antlib:org.apache.ivy.ant">
<target name="download" description="resolve dependencies with ivy">
<ivy:resolve />
<ivy:retrieve sync="true" type="jar"/>
</target>
</project>
ivy.xml, working
<?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="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.0.0" />
<dependency org="com.google.guava" name="guava" rev="13.0.1" />
</dependencies>
</ivy-module>
ivy.xml, not working
<?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="example" module="example" status="integration">
</info>
<dependencies>
<dependency org="com.github.fge" name="json-schema-validator" rev="2.2.1" />
<dependency org="com.google.guava" name="guava" rev="16.0.1" />
</dependencies>
</ivy-module>
eviction notice:
[ivy:resolve] :: evicted modules:
[ivy:resolve] com.google.code.findbugs#jsr305;1.3.9 by [com.google.code.findbugs#jsr305;2.0.1] in [default]
#Julien thanks for the hint, according to the example there I changed the retrieve line to
<ivy:retrieve pattern="lib/[artifact]-[revision].[ext]" sync="true"/>
and it works now.
Here is my error message, I'll explain below.
<error message="Mouse is not implemented yet for the remote WebDriver." type="java.lang.UnsupportedOperationException">java.lang.UnsupportedOperationException: Mouse is not implemented yet for the remote WebDriver
The problem is when I run my selenium automation scripts using ant/ivy I get that error. This code runs fine on it's own, but i'm trying to use ant/ivy to get it built so I can run it on jenkins. It does build ok, I get this problem when running the build suite.
I have the following selenium packages being pulled from the central repository
<dependency org="org.seleniumhq.selenium" name="selenium-server" rev="2.5.0"/>
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.5.0"/>
<dependency org="org.seleniumhq.selenium" name="selenium-firefox-driver" rev="2.5.0"/>
<dependency org="org.seleniumhq.selenium" name="selenium-api" rev="2.5.0"/>
<dependency org="org.seleniumhq.selenium" name="selenium-remote-client" rev="2.0b1"/>
<dependency org="org.seleniumhq.selenium" name="selenium-remote-driver" rev="2.5.0" >
<artifact name="selenium-remote-driver" type="jar" />
</dependency>
<dependency org="org.seleniumhq.webdriver" name="webdriver-common" rev="0.9.7376" >
<artifact name="webdriver-common" type="jar" />
</dependency>
<dependency org="org.seleniumhq.webdriver" name="webdriver-remote-client" rev="0.9.7376" >
<artifact name="webdriver-remote-client" type="jar" />
</dependency>
<dependency org="org.seleniumhq.webdriver" name="webdriver-remote-server" rev="0.9.7376" >
<artifact name="webdriver-remote-server" type="jar" />
</dependency>
<dependency org="org.seleniumhq.webdriver" name="webdriver-remote-common" rev="0.9.7376" >
<artifact name="webdriver-remote-common" type="jar" />
I wasn't able to find a place in the central repository to pull down the selenium-server-standalone.jar so I don't have that. Is there a package that might work better or a workaround for this issues?
Please let me know if my question is not clear enough, I'm new to ant/ivy.
Is it possible that you are hitting this issue? It seems like you are using an older version (2.5.0) of most of those Selenium packages. According to Maven Central those packages are all at version 2.19.0 now. Maybe updating to the most recent ones may fix the problem.
I'm using Ivy on my project, with the Ivy Eclipse plugin.
It appears that certain jars which are downloaded and added to my project are the javadoc jars, not the jars with the actual code. Note - this doesn't happen with all jars.
For example, adding this to my ivy.xml file:
<dependency org="junit" name="junit" rev="4.8.2"/>
caused the javadocs for junit to be downloaded and added to my classpath:
This breaks compilation for my project, as none of the unit tests are working.
This was working fine until I added a reference to Spring, and everything broke. I've tried removing the reference, and deleting junit from my local cache to force ivy to fetch it again, but the problem persists.
Here's my total dependency block (with spring removed):
<dependencies>
<dependency org="org.hamcrest" name="hamcrest-library" rev="1.3.RC2"/>
<dependency org="junit" name="junit" rev="4.8.2"/>
<dependency org="org.mockito" name="mockito-core" rev="1.8.5"/>
<dependency org="javax.persistence" name="persistence-api" rev="1.0"/>
</dependencies>
Here's my ivysettings.xml for the project:
<ivysettings>
<caches artifactPattern="[organisation]/[module]/[revision]/[artifact].[ext]" />
<settings defaultResolver="local.ibiblio.jboss.java-net.springsource" checkUpToDate="true" />
<resolvers>
<chain name="local.ibiblio.jboss.java-net.springsource">
<filesystem name="libraries">
<artifact pattern="${basedir}/ivy-repo/[artifact]-[revision].[type]" />
</filesystem>
<ibiblio name="ibiblio" m2compatible="true" />
<ibiblio name="jboss" m2compatible="true"
root="https://repository.jboss.org/nexus/content/groups/public-jboss" />
<ibiblio name="java.net" m2compatible="true"
root="https://repository.jboss.org/nexus/content/repositories/java.net-m2/" />
<ibiblio name="java.net" m2compatible="true"
root="http://repository.codehaus.org/" />
<url name="com.springsource.repository.libraries.release">
<ivy pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/libraries/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.libraries.external">
<ivy pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/libraries/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.bundles.release">
<ivy pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/release/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
<url name="com.springsource.repository.bundles.external">
<ivy pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
<artifact pattern="http://repository.springsource.com/ivy/bundles/external/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>
Some open source modules include optional java doc jars. To remove them add a configuration mapping to each of your dependencies:
<dependency org="junit" name="junit" rev="4.8.2" conf="default"/>
The default configuration in ivy is equivalent to the the compile scope in a maven module. This is how the optional libraries can be automatically omitted. (Check their POMs).
A better approach is to declare your own configurations and the default mapping as follows:
<configurations defaultconfmapping="compile->default">
<conf name="compile" description="Required to compile code"/>
<conf name="test" description="Additional test dependencies" extends="compile" />
</configurations>
Then in your ivy file you only need to declare the non-standard configurations:
<dependencies>
<dependency org="org.hamcrest" name="hamcrest-library" rev="1.3.RC2" conf="test->default"/>
<dependency org="junit" name="junit" rev="4.8.2" conf="test->default"/>
<dependency org="org.mockito" name="mockito-core" rev="1.8.5" conf="test->default"/>
<dependency org="javax.persistence" name="persistence-api" rev="1.0"/>
</dependencies>
In this case we only want the 3 test libraries to appear on the test configuration.
Still confused? The magic of ivy configurations is when you use them to manage your build's class path
<target name='dependencies' description='Resolve project dependencies and set classpaths'>
<ivy:resolve/>
<ivy:cachepath pathid="compile.path" conf="compile"/>
<ivy:cachepath pathid="test.path" conf="test"/>
</target>
This is what Maven is doing when you declare a scope tag on a dependency, for example:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
The scopes in Maven are fixed. In ivy you can have as many as you need.