Ivy not resolving transitive dependencies from public maven repos - java

Considering the following ivy dependencies,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
They depend on public maven repos mirrored by
http ://myivyserver:8888/mirrored/ .
as specified by the ivysettings resolver chaining to ...
<url name="mirrored" m2compatible="true">
<artifact
pattern="http://myivyserver:8888/mirrored/${maven2.artifact.pattern}" />
</url>
Where I can see the mirrored directory completely replicating the artefacts of remote maven repos.
I am used to Maven and the seeing the buildpath on eclipse showing maven dependencies.
Now, I am creating Ivy-dependency for a project. I am expecting to see similar, and I do see, a similar Ivy dependency node showing all the jars due to the Ivy eclipse pluggin.
However, the Ivy dependency node in eclipse buildpath does not show any jars transitively specified by the mirrored poms.
For example,
<dependency org="org.fusesource.restygwt" name="restygwt" rev="1.3"
conf="gwtcompile->default; compile->default"/>
<dependency org="org.jboss.resteasy" name="resteasy-jaxrs" rev="2.3.4.Final"
conf="compile->compile(*),runtime(*);runtime->runtime(*)"/>
both dependencies’ pom specify dependency on javax.ws.rs (jsr311-api)
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
However javax.ws.rs(jsr311-api) does not show up on the buildpath library of the ivy managed project, as a Maven managed one would.
What further more would I have to do to get ivy plugin to resolve transitive dependencies that are due to maven poms?
Thank you.

URL resolver considers maven layout but not pom dependencies. When I was implementing this functionality ibiblio resolver was able to resolve pom's dependencies.
http://ant.apache.org/ivy/history/latest-milestone/resolver/ibiblio.html
<ibiblio name="maven2" m2compatible="true" root="http://myivyserver:8888/mirrored">
I haven't used it long because I preferred non-transitive dependencies in my code so I've finished with using pure url resolver.

Related

NoClassDefFoundError when importing Tika 1.13 in Eclipse

I've done the following steps per the tika guide:
Add the tika-core and tika-parser dependencies to the pom.xml of the maven project
Run maven install from eclipse to produce tika-core jar and tika-parser jar
Add tika-core jar and tika-parser jar to my eclipse project build path
And I get this runtime exception when trying to run tika:
Exception in thread "main" java.lang.NoClassDefFoundError: org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
at com.ibm.hrl.ace.pdftotext.TikaExtracter.parse(TikaExtracter.java:33)
at com.ibm.hrl.ace.pdftotext.Main.AllPdfsToText(Main.java:116)
at com.ibm.hrl.ace.pdftotext.Main.main(Main.java:34)
Caused by: java.lang.ClassNotFoundException: org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException
at java.net.URLClassLoader.findClass(URLClassLoader.java:600)
at java.lang.ClassLoader.loadClassHelper(ClassLoader.java:786)
at java.lang.ClassLoader.loadClass(ClassLoader.java:760)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:326)
at java.lang.ClassLoader.loadClass(ClassLoader.java:741)
... 3 more
As far as I can see, when I build the jars using maven, it does add pdfbox properly... from the build log:
[INFO] Including org.apache.pdfbox:pdfbox:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:fontbox:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:pdfbox-tools:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:pdfbox-debugger:jar:2.0.1 in the shaded jar.
[INFO] Including org.apache.pdfbox:jempbox:jar:1.8.12 in the shaded jar.
And here are my maven dependencies:
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-core -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>1.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tika/tika-parsers -->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-parsers</artifactId>
<version>1.13</version>
</dependency>
</dependencies>
The problem is that if you manually add tika-core and tika-parsers jars in your build path you will not have the transitive dependencies that are listed in their own POM.
So I would suggest to:
Remove the tika-core and tika-parsers version that you have built yourself. Instead you should rely on the versions that are available on central. This will ensure that another one building your project will get the same jar (and not a locally built one)
You have two options
(Option A, use Maven) Do not add manually into Eclipse build path the jars. Rely either or built-in Maven plugin for Eclipse (m2e for instance) or use Eclipse plugin for maven (call mvn eclipse:eclipse to update .classpath and .project).
(Option B, without Maven) If you cannot use Maven for your project, you will have to add not only tika-parsers and tika-core jars, but all (most of) the transitive dependencies needed by these project (including for instance specific library per format [POI for Office, pdfbox for PDF...). You can get a list of the dependencies by typing mvn dependency:list in the folder containing the pom of tika-parsers.

How to publish artifacts to Artifactory with different names? [duplicate]

I published few atifacts of a component to a maven repository using different configurations of ivy. As an example, I took the following way (Ivy Documentation) to do the same..
<ivy-module version="1.0">
<info organisation="org.apache" module="filter"/>
<configurations>
<conf name="api" description="only provide filter framework API"/>
<conf name="homemade-impl" extends="api" description="provide a home made implementation of our api"/>
</configurations>
<publications>
<artifact name="filter-api" type="jar" conf="api" ext="jar"/>
<artifact name="filter-hmimpl" type="jar" conf="homemade-impl" ext="jar"/>
</publications>
</ivy-module>
According to the above configuration, the artifacts that are produced are filter-api.jar and filter-hmimpl.jar, and I generated a pom file filter.pom and published this into a maven repository.
Now, when I am trying to resolve the artifact filter-api in another component using the following..
<dependency org="org.apache" name="filter" rev="3.1" conf="default->api"/>
But it is not working, I believe my filter.pom should contain some modules like this, to make it work..
<modules>
<module>api</module>
<module>homemade-impl</module>
</modules>
Am I correct, and if yes how can I map different conf's of ivy to modules in maven.
Publishing mutliple files to a Maven repository is tricky because Maven modules normally contain a single artifact. Maven modules do support additional module artifacts, which are referenced in a Maven dependency using the "classifier" attribute.
The following answers provide examples of publishing multiple files to a Maven module:
how to publish 3rdparty artifacts with ivy and nexus
Convert ivy.xml to pom.xml
Observe that the ANT scripts are using the makepom to generate POM files and that these files are considered artifacts published (part of the ivy publications section).
For more background you might be interested in the following answer that deals with the differences between Maven "scopes" and ivy "confgurations".
How are maven scopes mapped to ivy configurations by ivy
Finally, if your ivy build uses configurations, it's possible to configure the makepom task to map between configurations and scopes:
<ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/${ivy.module}.pom"/>
<mapping conf="api" scope="compile"/>
</ivy:makepom>
Most likely, the problem is with the dependency declaration. You pull the dependency into your 'default' configuration with conf="default->api". But you really want them in the "compile" conf, to include them in your compile classpath.

Gradle mavenDeployer - how to include a separate modules code

I have a project like this:
MyProject
|-ModuleA
|-ModuleB
Module A is an Android Library that creates an aar, it has a dependency on Module B like so:
dependencies {
compile project(':ModuleB')
In ModuleA I am using mavenDepoyer to release locally:
uploadArchives {
repositories.mavenDeployer {
pom.groupId = "com.foo"
pom.artifactId = "bar"
pom.version = "1.0"
repository(url: "file://${localReleaseDest}")
}
}
This generates me an AAR file and a POM.
When uncompressed the AAR does not contain the class files from Module B
and the POM looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
As you can see this declares that the AAR has a dependency on ModuleB with an unspecified version. And so if I use this this AAR/POM as a remote, it fails to resolve the dependency ModuleB.
Error:A problem occurred configuring project ':example'.
Could not resolve all dependencies for configuration ':example:_debugCompile'.
Could not find MyProject:ModuleB:unspecified.
Searched in the following locations:
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar
Required by:
Test:example:unspecified > com.foo:MyProject:1.0
I do not want it to try and resolve Module B as another dependency, I want to use the mavenDeployer to be able to create the AAR & POM with Module B included inside, since I have the source code here to do that!
Searched the web to no avail, these sites gave hints but no answer:
How to publish apks to the Maven Central with gradle?
how to tell gradle to build and upload archives of dependent projects to local maven
http://www.gradle.org/docs/current/userguide/artifact_management.html
http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project
http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig
As far as I know, AARs don't include their dependencies (only APKs do). Instead, transitive dependency resolution will take care of resolving not only the AAR but also its dependencies. The unspecified version is most likely a result of not setting the project.version property in ModuleB.
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
The reason is your module dependencies is below :
compile project(':module B')
to resolve this issue, you should dependens maven dep
compile 'com.xxxxxx.xxx:xxxxx:1.0.0-SHNAPSHOT'

Ant: How to include only certain transitive dependencies from the artifact?

Just as an example, suppose I only need hamcrest in junit:
<dependency org="junit" name="junit" rev="4.7">
<include name="hamcrest*"/>
</dependency>
However it seems ant still pulls everything in junit. Maybe I misunderstood something?
Hamcrest is not longer a junit dependency. Take a look at the POM file for the module, the dependencies section is empty:
junit 4.7
Reportedly it has been incorporated into the junit jar (See MAVENUPLOAD-1651)
This explains why the following dependency will only retrieve a single jar:
<dependency org="junit" name="junit" rev="4.7"/>

Ivy can't resolve log4j from Maven Central

New to Apache Ivy, and can't get it to resolve the latest log4j jar from Maven Central. I'm using IvyDE to manage all of my dependencies and using all of its defaults, which I believe configure it to use either the Maven repo or Ibiblio.
This link takes you to Maven's log4j page. From here I am just using the Apache Ivy <dependency> tag provided on that page:
<dependency org="log4j" name="log4j" rev="1.2.16" >
<artifact name="log4j" type="bundle" />
</dependency>
When I add this to my ivy.xml file and save it inside Eclipse, IvyDE automatically runs an Ivy resolve...and I am getting an error:
Ivy resolve job of ivy.xml in 'myProject' has encountered a problem.
Impossible to resolve dependencies of myOrg#myProject;working#myMachine
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
download failed: log4j#log4j;1.2.16!log4j.bundle
(Those last 4 lines, although identical, are in fact repeated 4 times!)
Is something wrong with log4j on Maven Central? All of my other jars resolve without a hitch, and I am using the same technique for getting all of my jars. This is the only one (out of 30 or so) that is failing. Thanks in advance!
Leave out the
<artifact name="log4j" type="bundle" />
part and it will download the normal jar file.
I don't think you need the bundle-specification part and it seems (to me) like some kind of anomaly.
bundle is not even a core packaging value for maven:
The current core packaging values are: pom, jar, maven-plugin, ejb,
war, ear, rar, par. These define the default list of goals which
execute to each corresponding build lifecycle stage for a particular
package structure.
I used following :
<dependency org="log4j" name="log4j" rev="1.2.17">
<artifact name="log4j" type="jar" />
</dependency>
and it worked.

Categories