Maven dependencies from custom repository are not being included - maven

I am migrating my project from ant build to maven. For the third party dependencies, we have been using a custom maven repository (url http://SOME_IP/libs).I have defined this repository in my pom file and included these dependency like this :
<dependency>
<groupId>lib</groupId>
<artifactId>struts-core</artifactId>
<version>1.3.8</version>
<scope>runtime</scope>
</dependency>
Thus all dependencies are getting downloaded in .m2/repository/lib but when I run mvn compile it gives me compilation error saying that those package doesn't exist.

When you set scope to runtime, the dependencies are not available for compilation. You need to set scope to compile (or leave it out, which is the same).

Related

Maven not importing External Library into project after adding to .pom file in Intellij

I'm having trouble correctly importing a library into a project that I'm running. I have added the library as a dependency in the .pom, refreshed the pom, run mvn clean install, and I have set auto-import up so that the project gets updated correctly, but the project does not get added as an External Library, and I can't use it in my project. I get no errors. What am I doing wrong?
Here is the relevant part of my pom
..properties
<crowd.version>2.5.0</crowd.version>
.. end properties
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.atlassian.crowd</groupId>
<artifactId>crowd-integration-springsecurity</artifactId>
<version>${crowd.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</dependencyManagement>
Here is the question I was following to debug my error:
Import Maven dependencies in IntelliJ IDEA
I think you missed the point of dependency management; read more in official docs. This is a feature that you can centralize common dependency information that is then shared been different projects. All by itself, this definioition will not import the dependency.
What you probably want is just a plain dependency: drop the dependencyManagement tags, and move you dependency into the correct block in the pom.

A conflicting jar is being added to Maven dependencies - how to track down?

I have a dependency that I have added to my project:
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-server</artifactId>
<version>7.0.5</version>
</dependency>
When I compile and run I get an error indicating a mismatch of signatures. Looking at my Maven Dependencies in my Java Build Path (Eclipse) I see a jar being added by Maven for Vaadin version 6.8.8. I have scoured my pom.xml and do not see that I have added that. I assume that this dependency is being added by another dependency.
I definitely want to use Vaadin version 7.0.5. As long as version 6.8.8 keeps getting included it will be an issue. How can I resolve this?
mvn dependency:tree
Once you have its output you can add a suitable exclusion.

pom dependency fails in Gradle (ok in Maven)

I'm writing a standalone EJB client for JBoss 7.1 and as suggested I'm using the following dependency:
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<type>pom</type>
<version>7.1.1.Final</version>
</dependency>
This works as expected in Maven, however when used in Gradle like so:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final'
}
It fails with:
Could not find group:org.jboss, module:jboss-remote-naming, version:1.0.2.Final.
What is the reason for different behavior of Gradle vs. Maven?
Well the dependency you declare in Maven points to a pom packaging component, and the one in Gradle points to a jar. However there is no jar with this project since it is a pom packaging component so Gradle obviously fails.
http://search.maven.org/#browse%7C351478366
Using Gradle you probably have to either declare a dependency to the pom somehow (not sure if that is possible) or add the dependencies from the pom to your project yourself.
http://search.maven.org/remotecontent?filepath=org/jboss/as/jboss-as-ejb-client-bom/7.1.3.Final/jboss-as-ejb-client-bom-7.1.3.Final.pom
Use the #pom type:
dependencies {
compile 'org.jboss.as:jboss-as-ejb-client-bom:7.1.1.Final#pom'
}

Maven - Unable to resolve dependencies

Im trying to compile a Maven project. The compile fails however due to a "Failure to find xx.xxx.jar" in the repository i have specified in my settings.xml. I have access to this repository and when i navigate to the Url of the repository maven is trying to use i can see a pom file with the name of the jar but no jar. When i open the pom it contains the correct groupid and artificatid and jar name however the jar is not in the same directory.
Maven gives another error saying that "resolution will not be reattempted until the update interval of my repo-server has elasped or updated are forced".
What is happening here?
When maven goes to the repo i specify in settings.xml and finds a pom for the jar does it then try and go out to some external site to resolve the dependency or should the jar exist in the same folder as the pom?
What module are you attempting to download?
I discovered something similar with the following Maven central module:
http://search.maven.org/#artifactdetails|net.sf.json-lib|json-lib|2.4|jar
The Maven POM packaging declaration was jar, but no jar in Maven called "json-lib-2.4.jar"
When I looked at the files actually stored, I discovered that the author is providing two versions of the jar, each compiled for different versions of the JVM:
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk13</classifier>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

Errors using maven-bundle-plugin Embed-Dependency

I have a Maven project that's building fine, and I'm attempting to add a reference to twitter4j.
So I add this to the pom:
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[2.2,)</version>
<type>jar</type>
<optional>false</optional>
<scope>compile</scope>
</dependency>
When I build (mvn clean install) I get:
[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [twitter4j] by class(es) on the Bundle-Classpath[Jar:dot]: [net/stevex/tweetfetcher/impl/TweetFetcherImpl.class]
This makes sense .. the twitter4j package isn't embedded in the bundle. So I add an Embed-Dependency to the maven-bundle-plugin's instructions:
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
And now when I build, I get:
[ERROR] Error building bundle net.stevex.tweetfetcher:tweetfetcher-bundle:bundle:1.0-SNAPSHOT : Unresolved references to [dalvik.system, javax.crypto, javax.crypto.spec, javax.management, javax.management.openmbean, org.apache.commons.logging, org.apache.log4j, org.slf4j.impl, twitter4j.internal.http.alternative] by class(es) on the Bundle-Classpath[Jar:dot, Jar:twitter4j-core-2.2.3.jar]: [twitter4j/internal/logging/CommonsLoggingLogger.class, twitter4j/internal/logging/Log4JLoggerFactory.class, twitter4j/auth/OAuthToken.class, twitter4j/internal/http/HttpClientFactory.class, twitter4j/auth/OAuthAuthorization.class, twitter4j/internal/logging/Log4JLogger.class, twitter4j/conf/ConfigurationBase.class, twitter4j/TwitterAPIMonitor.class, twitter4j/internal/logging/CommonsLoggingLoggerFactory.class, twitter4j/management/APIStatisticsOpenMBean.class, twitter4j/internal/logging/Logger.class]
I don't understand why the twitter4j classes are missing, and I don't understand the references to dalvik.system, javax.crypto, etc. What's wrong here?
The problem is that the twitter4j project requires all of the packages listed in the error list. When you use it does not include all transitive dependencies. There is an Embed Transitive instruction for the maven-bundle-plugin that will embed all transitive dependencies
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
However, this kind of defeats the purpose of OSGi. This leaves you with two options that I know of:
Search for the packages in the second in the SpringSource EBR. You simply enter the package name in the search box, and the results will include the xml for your POM file. The SpringSource bundles will include references to other bundles in the EBR, eliminating the problem of transitive dependencies.
Use the bundle-all goal of the maven-bundle-plugin. This goal will run the maven bundle plugin for every dependency of your project, and place the resulting bundles into your target directory. You could then install these bundles into your local repository.
I would recommend using option 1 for as many of the bundles as you can find, then defaulting to option 2 when SpringSource doesn't have them.

Resources