How to specify an internal company Maven repo for a Jenkins job to use? - maven-2

I'm trying to setup a Maven2 job in Jenkins. I've got such lines in my pom.xml:
<distributionManagement>
<repository>
<id>releases</id>
<name>Releases</name>
<url>http://nexus.example.com:8081/nexus/content/repositories/releases</url>
</repository>
...
</distributionManagement>
I get this error when trying to build the job:
...
Downloading: http://repo1.maven.org/maven2/.../.../.../....jar
[INFO] Unable to find resource 'resource id goes here' in repository central (http://repo1.maven.org/maven2)
...
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
...Here goes the list of missing dependencies.
I know for sure that the required artifacts do exist in nexus.example.com repository, because I can do an mvn compile on my workstation and they will be downloaded OK.
But Jenkins for some reason does not even try to download the artifacts from local repo, ignoring the specification in the pom.xml.
Any ideas what can I try?

You can resolve this error in two ways.
One, move the <repositories> section out of <distributionManagement>. <distributionManagement> section is to indicate where you want to deploy your artifacts.
Specify the <repositories> section in the settings.xml of the username jenkins is running under. This is recommended, since this will apply for all the projects that you would be building.

Related

Maven: The Definitive Guide - POM for 'asm:asm-commons:pom:3.2:runtime' is invalid

I'm trying to go through the examples in Maven: The Definitive Guide. In chapter '4.3. Creating the Simple Weather Project' it has me run the following command.
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch04 -DartifactId=simple-weather -DpackageName=org.sonatype.mavenbook -Dversion=1.0
I think these errors are a problem.
[WARNING] POM for 'asm:asm-commons:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-commons at Artifact [asm:asm-commons:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-util:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-util at Artifact [asm:asm-util:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-analysis:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-analysis at Artifact [asm:asm-analysis:pom:3.2:runtime]
[WARNING] POM for 'asm:asm-tree:pom:3.2:runtime' is invalid. It will be ignored for artifact resolution. Reason: Failed to validate POM for project asm:asm-tree at Artifact [asm:asm-tree:pom:3.2:runtime]
because later I on get the message this
[INFO] Failed to resolve artifact.
Missing
--------
org.apache.maven.archetype:archetype-catalog:jar:1.0
org.apache.maven.archetype:archetype-common:jar:1.0
org.apache.maven.archetype:archetype-registry:jar:1.0
org.apache.maven.archetype:archetype-descriptor:jar:1.0
I ran the command again with debug on and I've included the output in a pastebin link
mvn archetype:create -DgroupId=org.sonatype.mavenbook.ch04 -DartifactId=simple-weather -DpackageName=org.sonatype.mavenbook -Dversion=1.0 --debug > mvnoutput.txt
http://pastebin.me/e50a3e5fa84cd8e8ff9336b3c3062d7f
I really have no idea why this is failing. I tried to navigate to the POMs manually using the
http://search.maven.org/remotecontent?filepath=asm/asm-commons/3.2/asm-commons-3.2.pom along with the other POMs and they look fine to me (but I'm trying to learn Maven.)
Here is my mvn effective settings. I left out the schema stuff at the very beginning. I am behind a proxy, but everything else seems to download fine. Any help would be much appreciated. I'll answer questions or post more information if you leave them as comments.
<localRepository>C:\Documents and Settings\~removed~\.m2\repository</localRepository>
<proxies>
<proxy>
<active>true</active>
<username>~removed~</username>
<password>~removed~</password>
<host>~removed~</host>
<nonProxyHosts>~removed~</nonProxyHosts>
<id>optional</id>
</proxy>
The most important thing is to start with Maven 3.0.4 instead of Maven 2.0.8. Furthermore you need to use:
mvn archetype:generate
instead of
mvn archetype:create
Take a look into the docs of the archetype plugin.
And one thing i recognized is that you are using an old book: Take a look into "Maven by Example" book and "Maven: The Complete Reference".

How to install third party source and javadoc JARs?

Is there way to install third party source and javadoc JARs by using maven?
Guide to installing 3rd party JARs
If you want to use the feature mentioned there about version 2.5 of the maven-install-plugin (if the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default by maven-install-plugin:2.5), then you can run:
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-fi‌​le -Dfile=<path-to-jar-file>
To generate the jars for the javadoc and the sources use e.g.:
Maven Deploy Plugin
Maven Javadoc plugin
Maven Source plugin
If you want to install a secondary artifact (such as the sources jar) for an already installed jar, then follow the step described here: Installing Secondary Artifacts
For info specifically about how to install 3rd party javadoc JARs see: How to deploy Javadoc jar file.
There are atleast three approaches in which 3rd party JARs can be added to Maven projects.
Install manually using mvn install command
Adding the location of jar file in pom dependency with the the following tag system
Creating a 'dummy' maven repository pointing to jar location.
I will focus on third approach which I find more cleaner and does not require any mvn command and works out of box from any IDE.
Step 1: Add the location of local 'dummy' repository in pom.xml
<repositories>
<repository>
<id>repo</id>
<name>repo</name>
<url>file:${project.basedir}/src/main/resources/lib</url>
</repository>
</repositories>
Here the 'dummy' repository location is the 'lib' folder of my project directory
Step 2 : Add the jar dependency into your pom.xml
<dependency>
<groupId>com.cloudera.impala</groupId>
<artifactId>impala-frontend</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
choose any groupId but make sure that artifactId and version is of the format <artifactId>-<version>.jar ( Name of 3rd party jar)
Step 3 : Create the folder structure as per the groupId,artifactId and version mentioned in the Step 2 in your local 'dummy' repository. So in this case the folder struction would be /src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/
Place your jar in the version folder and build your project.
You will get the following output which treats your 'dummy' repository to be the provider of your 3rd party jar.
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/maven-metadata.xml
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.pom
[WARNING] The POM for com.cloudera.impala:impala-frontend:jar:0.1-SNAPSHOT is missing, no dependency information available
[INFO] Downloading from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[WARNING] Could not validate integrity of download from file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar: Checksum validation failed, no checksums available
[WARNING] Checksum validation failed, no checksums available from repo for file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar
[INFO] Downloaded from repo: file:C:\Users\skumar\eclipse-workspace\chdQueryBuilder/src/main/resources/lib/com/cloudera/impala/impala-frontend/0.1-SNAPSHOT/impala-frontend-0.1-SNAPSHOT.jar (7.0 MB at 79 MB/s)
[INFO]

Why i always gets the [INFO] Unable to find resource in repository?

greetings all
I am using maven 2 in my spring project
and when I try to build the project from the terminal using the commands (mvn clean-mvn install)
it cannot download any dependency from any of the repos, and I always gets Info like :
Downloading: http://repo1.maven.org/maven2/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository first (http://repo1.maven.org/maven2)
Downloading: http://mirrors.ibiblio.org/pub/mirrors/maven2//velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository second (http://mirrors.ibiblio.org/pub/mirrors/maven2/)
Downloading: http://repository.jboss.com/maven2//velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository jboss (http://repository.jboss.com/maven2/)
Downloading: http://maven.jahia.org/maven2/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[INFO] Unable to find resource 'velocity-tools:velocity-tools-generic:pom:1.4' in repository additional (http://maven.jahia.org/maven2)
Downloading: http://208.79.234.53:8081/artifactory/libs-releases-local/velocity-tools/velocity-tools-generic/1.4/velocity-tools-generic-1.4.pom
[WARNING] Unable to get resource 'velocity-tools:velocity-tools-generic:pom:1.4' from repository host.varaza.com (http://208.79.234.53:8081/artifactory/libs-releases-local): Error transferring file: Connection timed out
any ideas, why such thing occurs ?
From the repository link, it looks like this dependency does not have an associated pom file. This is the reason for the warning.
Typically, dependencies in the repository also have a pom file, which describes the project, as well as specifies its dependencies. Maven first downloads this pom file, so that it can resolve transitive dependencies, if any.
Maven is just trying to get the pom files from your repositories and will try for as long as it can't download them.
This is happening most probably because the libraries (dependencies) you reference don't have a pom file in any of the remote repositories available. This is probably normal.
However if you want to get rid of the message you could deploy minimal pom files for those dependencies in your company's repository. You can choose to just install them locally but then other developers in your team would still have those messages.
Maven can't reach the sites where dependencies are located.
Try running
ping repo1.maven.org
or opening it in your web browser. Maybe you should set the firewall to allow Maven downloading stuff from internet.
I used the following dependency - works for me.
<dependency>
<groupId>velocity-tools</groupId>
<artifactId>velocity-tools-generic</artifactId>
<version>1.4</version>
</dependency>

maven settings.xml

I am trying to convert maven1 project.xml to maven 2 pom.xml.
maven one:convert plugin converts project.xml to pom.xml.
Tried the steps
Installed maven 2
cd project-dir (which has my project.xml)
mvn -e one:convert
I had maven-one-plugin-1.2.jar in $MAVEN_HOME/lib
Settings.xml had the following local repository settings
<localRepository>path_to_mavenhome/lib</localRepository>
<offline>true</offline>
<pluginGroups>
<pluginGroup>org.apache.maven.plugins:maven-one-plugin</pluginGroup>
</pluginGroups>
<profile>
<id>central</id>
<repositories>
<repository>
<id>local</id>
<url>file://pathtomavenhome\lib</url>
<layout>default</layout>
</repository>
</repositories>
</profile>
Got this error message
[INFO] Searching repository for plugin with prefix: 'one'.
[INFO] org.apache.maven.plugins:maven-one-plugin: checking for updates from central
[WARNING] repository metadata for: 'org.apache.maven.plugins:maven-one-plugin' could not be retrieved from repository: central due to an error: Error transferring file: Connection timed out: connect
[INFO] Repository 'central' will be blackliste
d
It does not connect to local repository.
No Settings.xml file in $M2_HOME/.m2 dir
I don't see the need for you to have a settings.xml here. Remove it from your home directory and try:
mvn one:convert
This should be more than sufficient.
If you're offline, there is no way for this to work, unless you already have the Maven one plugin in your local repository. Your settings.xml is not quite right and over-complicates your task at the moment.
Your steps are correct.
The error indicates that you have problem with your internet. Please verify the network availability.
[WARNING] repository metadata for: 'org.apache.maven.plugins:maven-one-plugin' could not be retrieved from repository: central due to an error: Error transferring file: Connection timed out: connect
Follow this links to for your reference
1. http://maven.apache.org/guides/mini/guide-m1-m2.html
2. http://maven.apache.org/plugins/maven-one-plugin/
Try mvn maven-one-plugin:convert
Just create new Settings.xml, check this example here Sample settings.xml for maven its usually located somewhere in your user dir, hidden folder called .m2

Why is my Maven so slow on Ubuntu?

I have Maven on Ubuntu server.
It seems to try lots and lots of places to download from but the download times out, but the timeout takes ages, so my whole build takes more than a hour.
Downloading: http://scala-tools.org/repo-releases/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository scala-tools.org (http://scala-tools.org/repo-releases)
Downloading: http://download.java.net/maven/2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[WARNING] Unable to get resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' from repository java.net (http://download.java.net/maven/2): Error transferring file: Connection timed out
Downloading: http://download.java.net/maven/1/org.apache.maven/poms/maven-repository-metadata-2.0.3.pom
[WARNING] Unable to get resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' from repository m1.java.net (http://download.java.net/maven/1): Error transferring file: Connection timed out
Downloading: http://download.java.net/maven/2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository maven2-repository.dev.java.net (http://download.java.net/maven/2)
Downloading: http://repository.jboss.org/maven2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
[INFO] Unable to find resource 'org.apache.maven:maven-repository-metadata:pom:2.0.3' in repository repository.jboss.org (http://repository.jboss.org/maven2)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-repository-metadata/2.0.3/maven-repository-metadata-2.0.3.pom
I only have two repos set in my maven build
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net Repository for Maven</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>repository.jboss.org</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/maven2</url>
</repository>
Thanks, philip
It seems that Ubuntu's packaged Maven version comes with a /etc/maven2/settings.xml. Have a look at this file to see if it contains additional repositories. Also check the file ~/.m2/settings.xml of the user you are using.
PS: I don't really like using .deb for this kind of software and recommend installing it "manually" (i.e. just download the archive, unzip it somewhere, set the M2_HOME env variable and add $M2_HOME/bin to the $PATH).
Maybe overkill if you're the only one working on the project but I'd recommend installing a Maven repository manager like Artifactory (http://www.jfrog.org/products.php) or Nexus. I'm not familiar with Nexus but Artifactory installation is dead simple - just unzip and you're good to go (since it comes with an embedded jetty).
Why will this make your Maven builds faster ?
Repository managers employ more sophisticated caching than the Maven core itself
(at least with Artifactory) You can restrict which Maven repositories are queried for which group IDs. This speeds up things considerably if you need to fetch dependencies from multiple different Maven repositories
Make sure you can access these resources (in your case the POMs) outside of Maven, if the machine has no network connectivity for example (or can't resolve hostnames), it will time out, and it will take a long time (as you noted).
If you don't need to re-download the resources every time, just run Maven in the "offline" mode with the -o switch.
Also, just a tip, you may want to create and install POMs, even for third party JARs, and then get them in your local repo. That way Maven will not have to go out to the tubes to get resources each time (it will check em, but they will be resolved locally).
For third party or otherwise non Maven JARs you can install then with the install plugin.