How to resolve project library via own mvn repository (artifactory) - intellij-idea

How can I link an maven repository that we set up internally with my Intellij?
In the project libraries view, I am able to add a new project library that resides in the standard maven reppositories but I do not see how to point IntelliJ to a specifiy maven repository, for example the artifactory that we set up for the company.
Settings.xml is also not recognized by Intellij. I post the settings.xml afterwards, it's not recognized though (password, username and company name have been replaced) :
<settings>
<servers>
<server>
<username>USER</username>
<password>PW</password>
<id>central</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<url>
https://dev.mycompany.com:8443/artifactory/any
</url>
<id>central</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots />
<id>central</id>
<url>
https://dev.mycompany.com:8443/artifactory/libs
</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots />
<id>central</id>
<url>
https://dev.mycompany.com:8443/artifactory/plugins
</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>

IntelliJ uses repositories from pom.xml for your maven project and settings.xml, your maven configuration file. In order to get dependencies from repote repository and by not adding pom.xml, I believe you should define repository in settings file.
By default, this file is located in your home folder like {home}/.m2/settings.xml
Try add this configuration:
<settings>
...
<profiles>
...
<profile>
<id>myprofile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>my-repo2</id>
<name>your custom repo</name>
<url>http://jarsm2.dyndns.dk</url>
</repository>
</repositories>
</profile>
...
</profiles>
<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>
...
</settings>
Also remember that you should either use profile while using maven or make it active by default. See more information here

Related

Maven won't deploy on Sonatype Nexus Repository

[Links are replaced with [http] because StackOverflow does not allow more than 2 links for me...]
I have installed Apache Maven 3.2.3 ([http]maven.apache.org/download.cgi?Preferred=ftp://mirror.reverse.net/pub/apache/), and it has downloaded all core plugins.
Then I installed Sonatype Nenus OSS ([http]www.sonatype.org/nexus/go/) as a WAR application on my XAMPP tomcat server.
Everything is well set and works.
My unique goal here is to test a deployment of a file from my local Maven to my Nexus repository.
Here is my POM file project:
<project xmlns="..."
xmlns:xsi="..."
xsi:schemaLocation="...">
<modelVersion>4.0.0</modelVersion>
<groupId>groupA</groupId>
<artifactId>artifactA</artifactId>
<version>1.0.0</version>
<distributionManagement>
<repository>
<id>releases</id>
<url>[http]localhost:8080/nexus-2.9.2-01/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
And here is my Maven configuration file: settings.xml
<settings xmlns="..."
xmlns:xsi="..."
xsi:schemaLocation="...">
<servers>
<server>
<id>releases</id>
<username>deployment</username>
<password>deployment123</password>
</server>
</servers>
The account provided is the default one and it works from the Nexus GUI.
My Nexus repository "releases" is configured as following:
[http]i.stack.imgur.com/Nh3dO.png
And when i use the following command:
mvn deploy
Or the following:
mvn deploy:deploy
Which are almost the same as far as I'm concerned...
Maven tells me this:
[http]i.stack.imgur.com/2vBNx.png
And the [Help 1] tells nothing but "see the plugin documentation". And the error message tells me that "The repository element is not specified in the POM file", but it actually is...
I really don't see what i am missing :/
Thanks for your help
Thank you all for your answers. I don't really have an idea why it works, but using these files works:
ArtifactA POM 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupA</groupId>
<artifactId>artifactA</artifactId>
<version>1.2.4</version>
<dependencyManagement>
<dependencies>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Test Repository</name>
<url>http://localhost:8080/nexus-2.9.2-01/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
ArtifactB POM 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>groupA</groupId>
<artifactId>artifactB</artifactId>
<version>1.0.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>groupA</groupId>
<artifactId>artifactA</artifactId>
<version>1.2.4</version>
<type>zip</type>
</dependency>
</dependencies>
</dependencyManagement>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Nexus Test Repository</name>
<url>http://localhost:8080/nexus-2.9.2-01/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
Maven settings file:
<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">
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<name>Nexus Test Repository</name>
<url>http://localhost:8080/nexus-2.9.2-01/content/repositories/releases</url>
<mirrorOf>*,!central</mirrorOf>
</mirror>
</mirrors>
</settings>
Deployment script:
mvn deploy:deploy-file \
-Dfile=artifactA_package.zip \
-Dpackaging=zip \
-DpomFile=pomA1.2.4.xml \
-Durl=http://localhost:8080/nexus-2.9.2-01/content/repositories/releases \
-DrepositoryId=nexus
mvn deploy:deploy-file \
-Dfile=artifactB_package.zip \
-Dpackaging=zip \
-DpomFile=pomB1.0.0.xml \
-Durl=http://localhost:8080/nexus-2.9.2-01/content/repositories/releases \
-DrepositoryId=nexus
Hope it will help the next one :)
I use wagon-webdav-jackrabbit pluging in combination with something like your configurations. It enables Maven to deploy artifacts and files to WebDAV enabled servers.
http://maven.apache.org/wagon/wagon-providers/wagon-webdav-jackrabbit/
Paste this in your pom.xml
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.4</version>
</extension>
</extensions>
</build>

maven setup another repository for certain dependency

I have Maven2 project. All dependencies except one are downloaded from public repository http://repo.maven.apache.org/maven2/.
But I have 1 dependency which I need to download from internal company's repository (we use Sonatype Nexus to store this dependency).
Also, I don't want to create full copy of public repo on my internal repo.
At this moment I have in pom.xml:
<url>http://maven.apache.org</url>
and
<repositories>
<repository>
<id>thirdparty</id>
<url>http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty</url>
</repository>
</repositories>
So, during build I see a lot of trash messages (in this case first line is a trash):
Downloading: http://<my_nexus_server_ip>:8081/nexus/content/repositories/thirdparty/ant/ant/1.6.5/ant-1.6.5.pom
Downloading: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom
Downloaded: http://repo.maven.apache.org/maven2/ant/ant/1.6.5/ant-1.6.5.pom (861 B at 3.2 KB/sec)
I want to clearly point Maven for which dependency it have to use internal repository and ignore it for others dependencies (and point that for others dependencies Maven2 have to use public repository).
Could you please help to implement such behavior in Maven?
Thanks In Advance!
According to this answer, it is not possible to set a specific repository for for some of the declared dependencies.
You need to configure the public repository group in Nexus to be used the only one in your Maven builds like the following:
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/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>
</settings>
You have to setup a separate repository in nexus like you described a repo called ThirdParty and add this repository into the configuration of the public repository group. Furthermore you need to upload the one dependency into that particular repository. Apart from that you should have to use the release and SNAPSHOT repository which means you need to configuration your distributionManagement accordingly in your company master pom file.

Error getting POM for 'org.codehaus.mojo:jasperreports-maven-plugin' from the repository

I am trying to deploy OSGI bundle to Jboss 7.1.1.Final. Everytime I compile and deploy project it gives me following error.
I have checked in M2, only 1.0-beta-2 version is present as we can see similar thing mentioned in repository too http://mvnrepository.com/artifact/org.codehaus.mojo/jasperreports-maven-plugin/1.0-beta-2
There is no version defined in POM, not sure from where it is trying to pull this version.
Command
mvn jboss-as:deploy -Pdomain -DskipTests -Dusername=manish -Dpassword=password -Dhost=x.x.x.x -Dport=9999 -X
POM Configuration
<repository>
<id>jboss-public-repository</id>
<name>JBoss Repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jasperreports</id>
<url>http://jasperreports.sourceforge.net/maven2</url>
</repository>
</repositories>
...
<plugins>
<!-- Jasper Plugins -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jasperreports-maven-plugin</artifactId>
<configuration>
<outputDirectory>${project.build.directory}/jasper</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile-reports</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.5</version>
</dependency>
</dependencies>
</plugin>
Error
Caused by: org.apache.maven.project.ProjectBuildingException: Error getting POM for 'org.codehaus.mojo:jasperreports-maven-plugin' from the repository: Failed to resolve artifact, possibly due to a repository list that is not appropriately equipped for this artifact's metadata.
org.codehaus.mojo:jasperreports-maven-plugin:pom:1.0-beta-3-SNAPSHOT
from the specified remote repositories:
central (http://repo1.maven.org/maven2),
jboss-public-repository (https://repository.jboss.org/nexus/content/groups/public)
for project org.codehaus.mojo:jasperreports-maven-plugin
at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:592)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromRepository(DefaultMavenProjectBuilder.java:251)
at org.apache.maven.project.artifact.MavenMetadataSource.retrieveRelocatedProject(MavenMetadataSource.java:163)
... 22 more
The jasperreport plugin is available via Maven central but not as a SNAPSHOT version. The question is if you need to use the SNAPSHOT version or the release version which can be found here.

Maven Failing download the JBoss dependency

Below are my maven settings from behind the proxy
User Settings:
<?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>D:\path\mvn_repo</localRepository>
<pluginGroups></pluginGroups>
<proxies>
<proxy>
<active>true</active>
<protocol>https</protocol>
<username>myusername</username>
<password>password</password>
<host>myproxyhost</host>
<port>myproxyport</port>
</proxy>
<proxy>
<active>true</active>
<protocol>http</protocol>
<username>myusername</username>
<password>password</password>
<host>myproxyhost</host>
<port>myproxyport</port>
</proxy>
</proxies>
<servers></servers>
<mirrors></mirrors>
<profiles></profiles>
</settings>
Global Settings:
<?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>D:\path\mvn_repo</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers></servers>
<mirrors></mirrors>
<profiles>
<profile>
<id>jboss-public-repository</id>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public-jboss/</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
</settings>
However I get 'Connection timed out' when I try to execute test goal.
This happens with both maven command line and M2Eclipse. What more settings do I require.
Maybe the proxy you are using requires NTLM authentication, which maven does not support.
You can try to use CNTLM:
http://cntlm.sourceforge.net/
JBoss repository has been moved in June 2011 causing many other users to experience problems like you describe. Most likely you need to change the URL in your pom.
For more details, refer to
How to configure jboss repository properly for my repository manager
and other answers listed as "Related" to above
JBoss wiki for maven users: Maven Getting Started - Users
PS. When doing the change, make sure to check all your poms that contain repository blocks because otherwise, broken JBoss URL may slip through these and kill your build

What repositories do you put in a generic pom file?

I am building a generic parent pom file for my projects.
In that file, I would like to have a list of most common Maven repositories, in order to have most dependencies available in the sub-projects (Jboss, Spring, etc.).
Here is this current pom:
<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>org.courtine</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<name>Parent</name>
<version>1.0</version>
<description>Common repositories</description>
<repositories>
<repository>
<id>javanet</id>
<name>Repository for Maven2</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>google</id>
<name>Google repository for Maven2</name>
<url>https://oss.sonatype.org/content/repositories/google-releases/</url>
</repository>
<repository>
<id>jboss</id>
<name>JBoss repository for Maven2</name>
<url>http://repository.jboss.org/maven2/</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
<repository>
<id>com.springsource.repository.libraries.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name>
<url>http://repository.springsource.com/maven/libraries/release</url>
</repository>
<repository>
<id>com.springsource.repository.libraries.external</id>
<name>SpringSource Enterprise Bundle Repository - External Library Releases</name>
<url>http://repository.springsource.com/maven/libraries/external</url>
</repository>
</repositories>
</project>
Is such a generic file listing common repositories a good idea?
Do you know other common public Maven repositories to put in such a generic pom file?
It is not a good idea to put repositories into a pom. Better use a Repository Manager like Nexus, Artifactory or Archiva.
In such kind of pom you should put things like default plugins with their appropriate revisions (pluginManagement) or dependencies which should be used (dependencyManagement).
Take a look for explanation into this. and take a look here how to setup this.
I have another option for doing what you want to do. You could using a profile in your settings.xml which reference all your repository for you (as an nexus/archiva will do).
I've posted something about his on my site.
Simply add this in your settings.xml:
<profile>
<id>my-repository</id>
<activation>
<!-- here we did not activat this profile by default -->
<activeByDefault>false</activeByDefault>
</activation>
<repositories>
<!-- list of standard repository -->
<repository>
<id>javanet</id>
<name>Repository for Maven2</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>google</id>
<name>Google repository for Maven2</name>
<url>https://oss.sonatype.org/content/repositories/google-releases/</url>
</repository>
<repository>
<id>jboss</id>
<name>JBoss repository for Maven2</name>
<url>http://repository.jboss.org/maven2/</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/release</url>
</repository>
<repository>
<id>com.springsource.repository.bundles.external</id>
<name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
<url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
<repository>
<id>com.springsource.repository.libraries.release</id>
<name>SpringSource Enterprise Bundle Repository - SpringSource Library Releases</name>
<url>http://repository.springsource.com/maven/libraries/release</url>
</repository>
<repository>
<id>com.springsource.repository.libraries.external</id>
<name>SpringSource Enterprise Bundle Repository - External Library Releases</name>
<url>http://repository.springsource.com/maven/libraries/external</url>
</repository>
<repository>
<id>intelligents-ia</id>
<name>Intelligents-ia Repository</name>
<url>http://intelligents-ia.com/maven2</url>
</repository>
</repositories>
</profile>
And you could build your project by adding -Pmy-repository on the command line:
mvn -Pmy-repository clean install
Or activate this profile by default by setting true on :
<activation>
<activeByDefault>true</activeByDefault>
</activation>