How to disable usage of public maven repo - maven

I've setup a maven repository(Artifactory) in my LAN which has no internet access. I've also change my maven settings.xml to use this internal repo only. However when I try to create a maven project, it still try to access the public repo(http://repo1.maven.org/maven2) for some downloads. Where has I done wrong?
For example, when I perform the following:
mvn archetype:generate -DgroupId=demo.john -DartifactId=struts2demo
-DarchetypeGroupId=org.apache.struts
-DarchetypeArtifactId=struts2-archetype-starter
-DinteractiveMode=false
there is the following waring reported:
... ...
[INFO] Generating project in Batch mode
[WARNING] Error reading archetype catalog http://repo1.maven.org/maven2
org.apache.maven.wagon.TransferFailedException: repo1.mavne.org
at org.apache.maven.wagon.shared. ...
... ...
Sometimes the it build successfully with this waring, but sometime it won't.
Below is my maven's settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<id>central</id>
<username>admin</username>
<password>password</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror>
<id>my-company-repo</id>
<name>A maven repo in local network</name>
<url>http://my.internal.server/artifactory/repo<url>
</mirror>
<mirrorOf>*</mirrorOf>
</mirrors>
<profiles>
<profile>
<id>artifactory</id>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://my.internal.server/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://my.internal.server/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://my.internal.server/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://my.internal.server/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>

Related

adding multiple repositories in maven settings xml

I have tried to refer two repository from nexus in the setting.xml file, but it fails at first url and does not go to the next one. is there a mistiake in my xml.(nexus group does work, but we want to know the solution of how to work with diff repo in setting xml)
<settings>
<servers>
<server>
<id>maven</id>
<username>username</username>
<password>password</password>
</server>
<server>
<id>jenkins</id>
<username>username</username>
<password>password</password>
</server>
</servers>
<mirrors>
<mirror> <!--This sends everything else to /public -snapshots-->
<id>maven</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus_example.net/repository/Maven_Proxy/</url>
<!--<url>http://localhost:8081/repository/maven-proxy/</url>-->
</mirror>
<mirror> <!--This sends everything else to /public -snapshots-->
<id>jenkins</id>
<mirrorOf>*</mirrorOf>
<url>https://nexus_example.net/repository/Jenkins_Proxy/</url>
<!--<url>http://localhost:8081/repository/maven-proxy/</url>-->
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>maven</id>
<url>https://nexus_example.net/repository/Maven_Proxy/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>jenkins</id>
<url>https://nexus_example/repository/Jenkins_Proxy/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
Your first mirror is a <mirrorOf> everything, and so the second mirror is never used.

Nexus group by SNAPSHOT

I have Nexus with builds repository. How I can group my versions on folders named snapshot-x.x ?
Repository have snapshot type. User deployment have all privileges.
I run maven as mvn versions:set -DnewVersion=$VERSION and mvn clean deploy -B -Pbuild -Dbuild.version=$VERSION
My settings.xml work only releases repo ;-(
<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>
</server>
</servers>
<profiles>
<profile>
<id>build</id>
<repositories>
<repository>
<id>nexus-repo</id>
<name>Nexus repo</name>
<url>http://<MY-HOST>:8081:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-repo</id>
<name>Nexus repo </name>
<url>http://<MY-HOST>:8081/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<altDeploymentRepository>
-DaltDeploymentRepository=builds::default::http://deployment:<MY_PASS>#<MY-HOST>:8081/content/repositories/builds
</altDeploymentRepository>
</properties>
</profile>
</profiles>
</settings>
<activeProfiles>
<activeProfile>build</activeProfile>
</activeProfiles>
I'm not sure what you are asking for? A repository has a fixed format which comprises of groupId:artifactId:version ?
There you see com/soebes/examples/j2ee is the groupId: com.soebes.examples.j2eee and than artifactId: app plus the version 1.1.2-SNAPSHOT with the underlying versions for a single SNAPSHOT

How to set up maven?

How to set up Maven (settings.xml) and Artifactory to access all repositories through Artifactory?
My current settings are as follows and I even fail to get the Maven-deploy plugin
to execute. The error is that it was not found in any repos (local + artifactory)
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
<server>
<username>xxx</username>
<password>xxx</password>
<id>central</id>
</server>
<server>
<username>xxx</username>
<password>xxx</password>
<id>snapshots</id>
</server>
</servers>
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>repo</name>
<url>http://[host]:[port]/artifactory/repo</url>
<id>repo</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://[host]:[port]/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://[host]:[port]/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://[host]:[port]/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://[host]:[port]/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
[host]:[port] are real in file and so is [username][password] checked that 3 times.
[ERROR] No plugin found for prefix 'deploy' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\[username]\.m2), repo (http://[host]:[port]/artifactory/repo)] -> [Help 1]
Artifactory can generate the right settings.xml file for you. Look for Maven Settings link on the right side menu of the home screen.

Using Nexus repository instead of public Maven in Idea Intellij

How can I force Idea Intellij to download from Nexus repository instead of Maven Public repo?
Where can I configure that in Idea properties?
It's not defined in pom.xml files and I'd prefer not to.
Not sure if it will work also on Idea Intellij ( I am using spring source studio - eclipse clon) , but should because maven configuration is in settings.xml in .M2 directory which is located in your home directory. Just use something like this ( my server is running on nexus-server:8081):
<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>releases</id>
<username>user-name</username>
<password>your-password</password>
</server>
<server>
<id>snapshots</id>
<username>user-name</username>
<password>your-password</password>
</server>
</servers>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://nexus-server:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Disable 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>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

Maven deploy error

I have maven project with several modules. Need to deploy all modules(jars and one resulting war) into remote Artifactory server.
So in settings.xml I am added config:
<?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">
<servers>
<server>
<username>admin</username>
<password>password</password>
<id>central</id>
</server>
<server>
<username>admin</username>
<password>password</password>
<id>snapshots</id>
</server>
</servers>
<profiles>
<profile>
<repositories>
<repository>
<id>central</id>
<name>libs-release</name>
<url>http://192.168.1.120:8088/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://192.168.1.120:8088/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://192.168.1.120:8088/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://192.168.1.120:8088/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
Main pom have section:
<distributionManagement>
<repository>
<id>central</id>
<url>http://192.168.1.120:8088/artifactory/libs-release-local</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.1.120:8088/artifactory/libs-snapshot-local</url>
</snapshotRepository>
</distributionManagement>
And all modules have 1.0-SNAPSHOT version.
But when executing the command: >mvn deploy, the Following error occured:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-deploy-plugin:2.5:deploy
(default-deploy) on project jobic: Failed to deploy artifacts: Could
not transfer artifact *project-name:project-nam*e:pom:0.0.1 from/to central
(http://192.168.1.120:8088/artifactory/libs-release-local): Failed to
transfer file:
http://192.168.1.120:8088/artifactory/libs-release-local/project-name/project-name/0.0.1/project-name-0.0.1.pom.
Return code is: 401 -> [Help 1]
How to deal with it?
UPDATE:
Ok, I got it. The 401 error says: 401 = "Unauthorized" . So I added proper username/password into settings.xml. Seems work now.
Have one last question: it is right, that I am using SNAPSHOT suffix in the version? Is it proper behavior for situation, when I need do deploy all modules onto remote repo? How to deal with situation, when the one module was broken and my coworkers need to use previous version of this module?
It might be because it is written incorrectly.
You can change it hhttp to http and try again.

Resources