How to specify a repository for a dependency in Maven - maven-2

In projects with several dependencies and repositories, the try-and-error approach of Maven for downloading dependencies is a bit cumbersome and slow, so I was wondering if there is any way to set an specific repo for some declared dependencies.
For example, I want for bouncycastle to check directly BouncyCastle's Maven repo at http://repo2.maven.org/maven2/org/bouncycastle/ instead of official Maven.

Not possible. Maven checks the repositories in their declaration order until a given artifact gets resolved (or not).
Some repository manager can do something approaching this though. For example, Nexus has a routes feature that does something equivalent.

I have moved libraries from 3rd party repositories to their own project and included this project as first module in my base project:
base/pom.xml
...
<modules>
<module>thirdparty</module>
<module>mymodule</module>
...
</modules>
base/thirdparty/pom.xml:
...
<artifactId>thirdparty</artifactId>
<packaging>pom</packaging>
<repositories>
<repository>
<id>First thirdparty repository</id>
<url>https://...</url>
</repository>
...
</repositories>
<dependencies>
<dependency>
<!-- Dependency from the third party repository -->
</dependency>
....
</dependencies>
base/mymodule/pom.xml:
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>thirdparty</artifactId>
<version>${project.version}</version>
<type>pom</type>
</dependency>
...
</dependencies>
This will ensure that the libraries from the thirdparty repository are downloaded into the local repository as soon as the root project is build. For all other dependencies the repositories are not visible and therefore not included when downloading.

This post could be very old but might be useful to someone. I specified the two repositories in pom.xml like below and it worked.
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>http://repository.aspose.com/repo/</url>
</repository>
<repository>
<id>Default</id>
<name>All apart from Aspose</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

Related

bamboo java specs with extra maven repository

I use bamboo 7.2.2 as a CI engine with java specs. I am trying to build some reusable bamboo stages/jobs/tasks. Develop once, publish to a private maven repository, and then reuse them in various other bamboo plans by defining the dependency in the pom.xml.
As the library is published in a private repository, I have to define the repository in the pom.xml.
The problem is that at runtime, bamboo merges my pom.xml with some template of its own and removes the repository definition.
Is there any other option to define multiple maven repositories for bamboo java specs?
No way other than modifying the template pom.xml on the Bamboo server.
Note however, that you'll have to wait for 24 hours (the Maven default) to see your changes in the common specs library. Unless of course, you bump the common specs version and manually update the template pom.xml again.
We do exactly what you describe and don't appear to have any problems. We're able to use our custom shared classes in our Bamboo Specs. This is the pom.xml for one of our apps.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.atlassian.bamboo</groupId>
<artifactId>bamboo-specs-parent</artifactId>
<version>7.2.3</version>
<relativePath />
</parent>
<groupId>com.example.someapp</groupId>
<artifactId>bamboo-specs</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<repositories>
<repository>
<id>nexus</id>
<name>Internal Nexus Repository</name>
<url>https://mvn.example.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>custom-bamboo-specs</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
</project>
The only weird behaviour we have is that we can't have two apps building with different versions of this custom library - Bamboo gets really confused until we bring them all in line. Other than that, it works.
Bamboo version: 7.2.10

Oracle jdbc jar unable to down load in maven plugin

[WARNING] The POM for com.oracle:ojdbc7:jar:12.1.0 is missing, no dependency information available
<!-- Oracle JDBC driver -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0</version>
</dependency>
<!-- HikariCP connection pool -->
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.6.0</version>
</dependency>
The latest release of the oracle jdbc driver is available in maven central since a few days (september 2019, announced at Oracle CodeOne), there is no longer a need to install it locally or add obscure other repositories.
See https://medium.com/oracledevs/oracle-jdbc-drivers-on-maven-central-64fcf724d8b
The coordinates are
<!-- https://mvnrepository.com/artifact/com.oracle.ojdbc/ojdbc8 -->
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>
ojdbc7 is absent in the maven central repository
You need to download jar from oracle.com.
Currently it can be downloaded here. Registration is needed.
https://www.oracle.com/database/technologies/jdbc-upc-downloads.html
Then import ojdbc7.jar into your local maven repository with the following command
mvn install:install-file -Dfile=ojdbc7.jar -DgroupId=com.oracle -DartifactId=ojdbc7 -Dversion=12.1.0.2 -Dpackaging=jar -DgeneratePom=true
Alternatively, if your team has it's own remote maven repository, import it there.
edit: fixed mvn command and link
Add repository to your build and download:
See on mvnrepository.com
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>HandChina-RDC</id>
<name>HandChina RDC</name>
<url>http://nexus.saas.hand-china.com/content/repositories/rdc/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
</dependencies>
</project>

where is the correct and recent ehcache maven repository

I've been struggling to get ehcache 2.1.0 in my environment. Anytime I thought I got it right, it's just not downloading it. Here is where I set the repository:
<repository>
<!--<url>https://oss.sonatype.org/content/repositories/releases/</url>-->
<url>http://oss.sonatype.org/content/repositories/sourceforge-releases</url>
<id>sonatype-mirror</id>
<layout>default</layout>
<name>Repository for library including ehcache recent ones</name>
</repository>
And I add the dependency this way :
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.1.0</version>
</dependency>
Is there anything that's i'm doing wrong or not properly?
Ehcache is available in the maven central repository, there is no need to add a particular repository.
However, the ehcache artifact is special, it's an "aggregating" artifact which is of type pom. So the dependency should be declared like this:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.1.0</version>
<type>pom</type>
</dependency>
Of course, you can also declare dependencies on individual modules if you want (e.g. ehcache-core) in which case you don't need to specify the type.
References
Ehcache Documentation
Java Requirements and Dependencies
net.sf.ehcache:ehcache:2.1.0 is a dependency of type pom therefore you need to specify it:
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.1.0</version>
<type>pom</type>
</dependency>
See also:
3.6. POM Best Practices

java.net maven repo - JMS artifact missing

I just created a new Maven project using the default archetype and added the following dependency to my POM file.
<dependencies>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
Realizing that the Sun's JARs are not on Maven central due to licensing issues, I added
the following Maven repo to my POM (I know this is bad practice though and that it needs to be added to a settings.xml)
<repositories>
<repository>
<id>Repo ID</id>
<layout>default</layout>
<name>Java.net Maven repo</name>
<releases>
<enabled>true</enabled>
</releases>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
I still see this error in my POM file.
"Missing artifact javax.jms:jms:jar:1.1:compile"
Does anyone here know what else needs to be done in addition to the config I already have?
Realizing that the Sun's JARs are not on Maven central due to licensing issues, I added
the following Maven repo to my POM
Yeah, but http://download.java.net/maven/2/javax/ doesn't have the jms artifact...
The good news is that the JBoss Nexus repository does have it:
<repository>
<id>repository.jboss.org-public</id>
<name>JBoss repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
If you just want the jms artifact and don't want to add the whole repo, you can do the following:
wget https://repository.jboss.org/nexus/content/groups/public/javax/jms/jms/1.1/jms-1.1.jar
mvn -e install:install-file -Dfile=./jms-1.1.jar -DartifactId=jms -DgroupId=javax.jms -Dversion=1.1 -Dpackaging=jar
In fact the real solution for this issue is to use the jms-api-1.1-rev-1.jar artifact available on Maven Central : http://search.maven.org/#artifactdetails%7Cjavax.jms%7Cjms-api%7C1.1-rev-1%7Cjar

google salve - maven

I tried to install google salve http://code.google.com/p/salve/ by adding following statements in the project's pom file:
However, when running mvn dependency:resolve it states "unable to find resource "salve:salve:jar:2.0" in repository salve
What's wrong?
<dependency>
<groupId>salve</groupId>
<artifactId>salve</artifactId>
<version>2.0</version>
</dependency>
<repository>
<id>salve</id>
<name>Google Maven Repository</name>
<url>http://salve.googlecode.com/svn/maven2/</url>
</repository>
The salve artifact you're mentioning is a pom (and indeed, there is no salve:salve:jar:2.0). If this is really the dependency you want to declare, you need to specify the type:
<project>
...
<repositories>
<repository>
<id>salve</id>
<name>Google Maven Repository</name>
<url>http://salve.googlecode.com/svn/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>salve</groupId>
<artifactId>salve</artifactId>
<version>2.0</version>
<type>pom</type>
</dependency>
...
</dependencies>
</project>
Honestly, I doubt you want the pom but I can't tell you which artifact you need.
Update: I guess you would have figured this out yourself but for salve-depend-guice, use the following dependency:
<dependency>
<groupId>salve</groupId>
<artifactId>salve-depend-guice</artifactId>
<version>2.0</version>
</dependency>
The dependencies of the above artifact will be downloaded transitively by Maven.