Jenkins cannot find maven dependency from local repository - java

I have added a jar file to my local maven repository by mvn install: install-file which works fine on my local machine. This is the dependency in my pom:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>${oracle.connector.version}</version>
</dependency>
When running mvn clean install on my machine, everything works just fine.
Now I have a local jenkins instance running (on a Windows machine) which should build my project. The build runs into an error and jenkins says:
Could not find artifact com.oracle:ojdbc6:jar:11.2.0 in mirror1 (http://repo.maven.apache.org/maven2) -> [Help 1]
The project settings for jenkins looks like this:
<?xml version="1.0" encoding="UTF-8" ?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
"http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/
settings-1.0.0.xsd">
<localRepository>${user.home}/.m2/repository</localRepository>
<servers>
<server>
<id>nexusReleases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
<server>
<id>nexusSnapshots</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>mirror1</id>
<mirrorOf>*</mirrorOf>
<name>Maven2 official repo</name>
<url>http://repo.maven.apache.org/maven2</url>
</mirror>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
And of course I've double checked the repository directory in .m2 . The ojdbc6.jar is there.
So what's wrong with my setup?

You might want to check what Jenkins uses as its local repository.
Go to Jenkins verwalten (Manage Jenkins)
Under Maven-Projekt-Konfiguration (Maven project configuration), there should be a setting where the .m2 repository for Jenkins is located.
If that was not the same repository you were using locally, that would explain your error.
Edit: There is also an option for each job whether or not to use a "private repository". That repository will be specific to that job and not share artifacts with any other.

I had the same issue with ojdbc8.jar. The build failed with this dependency in my pom.xml.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3</version>
</dependency>
I copied the ojdbc8.jar to the Jenkins maven repository. After renaming it to ojdbc8-19.3.jar my build was successful.
Perhaps this helps someone else.

Use the following dependency:
<dependency>
<groupId>com.oracle.ojdbc</groupId>
<artifactId>ojdbc8</artifactId>
<version>19.3.0.0</version>
</dependency>

Related

Deployment failed: repository element was not specified in the POM inside distributionManagement element [duplicate]

I am trying to run the command, mvn release:perform, but I get this error:
Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project git-demo:
Deployment failed: repository element
was not specified in the POM inside
distributionManagement element or in
-DaltDeploymentRepository=id::layout::url
parameter
Here's my pom.xml file:
<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>
<groupId>com.sonatype.blog</groupId>
<artifactId>git-demo</artifactId>
<packaging>jar</packaging>
<version>1.1-SNAPSHOT</version>
<name>git-demo</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<scm>
<connection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</connection>
<url>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</url>
<developerConnection>scm:git:git#github.com:Christian-Achilli-KP/git-demo.git</developerConnection>
</scm>
<distributionManagement>
<!-- use the following if you're not using a snapshot version. -->
<repository>
<id>localSnap</id>
<name>RepositoryProxyRel</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/releases/</url>
</repository>
<!-- use the following if you ARE using a snapshot version. -->
<snapshotRepository>
<id>MylocalSnap</id>
<name>RepositoryProxySnap</name>
<url>http://127.0.0.1:8080/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.1</version>
</plugin>
</plugins>
</build>
</project>
Actually I can see the
repository
declaration inside the
distributionManagent
tag.
Here's my settings.xml:
<settings>
<servers>
<server>
<id>localSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>MylocalSnap</id>
<username>deployment</username>
<password>****</password>
</server>
<server>
<id>myserver</id>
<username>tomcat</username>
<password>tomcat</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://127.0.0.1:8080/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<properties>
<project.build.sourceEncoding>MacRoman</project.build.sourceEncoding>
<project.reporting.outputEncoding>MacRoman</project.reporting.outputEncoding>
</properties>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Any advice why it complains?
Review the pom.xml file inside of target/checkout/. Chances are, the pom.xml in your trunk or master branch does not have the distributionManagement tag.
I got the same message ("repository element was not specified in the POM inside distributionManagement element"). I checked /target/checkout/pom.xml and as per another answer and it really lacked <distributionManagement>.
It turned out that the problem was that <distributionManagement> was missing in pom.xml in my master branch (using git).
After cleaning up (mvn release:rollback, mvn clean, mvn release:clean, git tag -d v1.0.0) I run mvn release again and it worked.
You can also override the deployment repository on the command line:
-Darguments=-DaltDeploymentRepository=myreposid::default::http://my/url/releases
The ID of the two repos are both localSnap; that's probably not what you want and it might confuse Maven.
If that's not it: There might be more repository elements in your POM. Search the output of mvn help:effective-pom for repository to make sure the number and place of them is what you expect.
For me, this was something as simple as a missing version for my artifact - "1.1-SNAPSHOT"

Add mysql connector to a maven / nexus build in eclipse

I'm trying to connect to a mysql database in java and so I have to add mysql-connector-java:jar to my eclipse project. The integration with maven is not working though.
Here is what I have in my settings.xml:
<profile>
<id>default</id>
<properties>
<mvn.path>.../maven-3.0.4/bin/mvn.bat</mvn.path>
<javac.5>...bin/javac.exe</javac.5>
<javac.6>..../javac.exe</javac.6>
</properties>
<repositories>
<repository>
<id>central-repository</id>
<name>OSS central Maven Release Repository</name>
<url>https://oss.sonatype.org/content/repositories/releases</url>
</repository>
<repository>
<id>public-repository-main</id>
<name>Central Repository</name>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>public-repository</id>
<name>OSS Maven Release Repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
</repository>
</repositories>
</profile>
<interactiveMode>true</interactiveMode>
<!-- offline
| Determines whether maven should attempt to connect to the network when executing
| a build.
| This will have an effect on artifact downloads, artifact deployment, and others.
|
| Default: false <offline>false</offline> -->
<offline>false</offline>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
And here is the error I get when I try to a mvn clean install
Failure to find mysql:mysql-connector-java:jar:5.0.5 in
http://xxxx:8083/nexus/content/groups/public
How can I force nexus to download the artifact from my public repositories to nexus? Do I have to add it manually?
You need to tell maven to use your maven repository. To do this, modify $HOME/.m2/settings.xml as follows:
<?xml version="1.0" encoding="UTF-8"?>
<settings 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/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxxx:8083/nexus/content/groups/public</url>
</mirror>
</mirrors>
<proxies></proxies>
<servers></servers>
<pluginGroups></pluginGroups>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
The nexus profile is configured to download from the central repository with a bogus URL of http://central.
This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.
Suppose you have repository Central that has repository path http://xxxx:8083/nexus/content/repositories/central and also point Remote Storage Location to http://repo1.maven.org/maven2/ you can change http://central to http://xxxx:8083/nexus/content/repositories/central or http://repo1.maven.org/maven2/.
in your pom.xml, use below dependency to getting mysql-connector.
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.33</version>
</dependency>
See also: Getting started with Nexus maven repository manager
Hope this help.
Is there a chance that you have included two different versions for mysql-connector-java?
I used to have an error like that, it turned out I had accidentally included another version, so this specific version was not accessed (it was a transitive dependency, which for peculiar reasons I could not exclude). I moved the dependency in the beginning of all other dependencies (in your case it might be in the end),and it worked. Theoretically having two versions of same dependency should not throw an error.
Here are the available versions of MySQL connector
http://mvnrepository.com/artifact/mysql/mysql-connector-java , click on any version, it will give your the dependency.

Proxy SVN Google Code based maven repository in Sonatype Nexus

I have set up the Sonatype Nexus for repository caching.
com.googlecode.htmleasy is not being resolved by maven. Getting error
Failure to find com.googlecode.htmleasy:htmleasy:jar:0.7 in
http://localhost:8081/nexus/content/groups/public was cached in the
local repository, resolution will not be reattempted until the update
interval of nexus has elapsed or updates are forced -> [Help 1]
htmleasy is one artifact which is sitting inside google code based maven repo.
<repository>
<id>htmleasy</id>
<url>http://htmleasy-maven.googlecode.com/svn/trunk/</url>
</repository>
But What should I do so that when I refer following artifact based on above repo
<dependency>
<groupId>com.googlecode.htmleasy</groupId>
<artifactId>htmleasy</artifactId>
<version>0.7</version>
</dependency>
gets resolved by my maven ?
My maven settings xml looks like as follows,
<?xml version="1.0" encoding="UTF-8"?>
<settings 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/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<proxies></proxies>
<servers></servers>
<pluginGroups></pluginGroups>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Add a new proxy repository and do not forget to add it to your 'public' repository group.
(If you still get "resolution will no be reattempted" error from maven, try calling maven with '-U'.)

How can I tell Maven search only in intranet Repository(Artifactoy) and not in Internet

I installed maven and Artifactory.
Artifactory has an internet connection.
I configured Maven in this way.
<?xml version="1.0" encoding="UTF-8"?>
<settings
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"
xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<localRepository>X:/.m2/repository</localRepository>
<interactiveMode>true</interactiveMode>
<usePluginRegistry>false</usePluginRegistry>
<offline>false</offline>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>MY_Artifactory</id>
<url>http://myServer/artifactory/repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>MY_Artifactory</id>
<url>http://myServer/artifactory/repo</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
How can I tell Maven that it searches only in Artifactory and that it should try direct with local internet?
<mirrors>
<mirror>
<id>local</id>
<name>Local Artifactory</name>
<url>http://url/for/artifactory</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
add this to settings.xml
If you have already configured profiles using below command you can call them.
mvn clean install -P dev
The above will use dev profile .
Edit: Other way is you can override built-in repositories .
Please go through this i feel it is helpful.
http://wiki.jfrog.org/confluence/display/RTF20/Configuring+Artifacts+Resolution
I would recommend to use:
<mirrorOf>*</mirrorOf>
since you want to only resolve dependencies in the intranet only all configured repositories (also those in transitive dependencies and weird pom.xml's) should use your internal repository. Not only central.

Archetype Selection Using m2eclipse

I would like to create a new Maven project in Eclipse using an archetype using the New Maven Project wizard. At the "Select an Archetype" step, I have three catalogs to choose from: Nexus Indexer, Internal and Default Local. I don't understand where the content for these catalogs should be coming from. If I click on the "Configure" button, they are all greyed out and I can't modify them.
Only the Internal catalog has any archetypes listed in it. Where are these archetypes coming from? It's not from my local Maven repository because the group/artifacts are not in it (and archetypes in the repo are not listed).
Why is the Nexus Indexer list empty? I've read some posts that the Nexus index needs to be updated, but not how to do this. Is this different than the repository indexes (which are scheduled to be updated daily).
As you can see, I'm a little confused about the whole catalog business and how Maven, m2eclipse and Nexus interact. Any clarification is most welcome!
My setup:
Eclipse: Helios Service Release 2 (Build id: 20110218-0911)
Apache Maven 3.0.3
m2eclipse: 0.12.1.20110112-1712 (set up to use external Maven install)
Sonatype Nexus™ Open Source Edition, Version: 1.9.0.2
My local Maven settings.xml looks like this:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://myserver:8080/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>my-snapshots</id>
<username>user</username>
<password>password</password>
</server>
<server>
<id>my-releases</id>
<username>user</username>
<password>password</password>
</server>
</servers>
</settings>
The default archetype catalog can contain new archetypes. It's a manual process, you've to add them to a custom .xml file within your ~/.m2 directory.
For more information : http://maven.apache.org/archetype/maven-archetype-plugin/specification/archetype-catalog.html
And for reference, here's a template archetype-catalog.xml
<?xml version="1.0" encoding="UTF-8"?>
<archetype-catalog>
<archetypes>
<archetype>
<groupId>com.spedge</groupId>
<artifactId>archetype-application-custom-filter</artifactId>
<version>1.0-SNAPSHOT</version>
</archetype>
</archetypes>
</archetype-catalog>
Additionally, here's a good link on SO about Archetypes : What are the URLs of all the Maven Archetype catalogs that you know about?

Categories