I have a private Nexus with a repository protected via authentication.
Pulling libraries works like a charm, but if I want to use one of the archetypes stored up there I always need to write plaintext username and password in the URL of the archetype catalog like this:
mvn archetype:generate -DarchetypeCatalog=http://username:[email protected]/nexus/content/repositories/myrepo/archetype-catalog.xml
I read http://maven.apache.org/archetype/maven-archetype-plugin/faq.html#authentication and updated my settings.xml with what I understood from that very tiny bit of help:
<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>myrepo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
<server>
<id>pretty-archetype-unicorn-repo</id>
<username>username</username>
<password>{HASHED_PASSWORD}</password>
</server>
</servers>
<profiles>
<profile>
<id>someid</id>
<repositories>
<repository>
<id>myrepo</id>
<name>My Repo</name>
<url>http://maven.mycompany.com/nexus/content/repositories/myrepo/</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>someid</activeProfile>
</activeProfiles>
</settings>
Needless to say, it doesn't work and when I try:
mvn archetype:generate -DarchetypeCatalog=http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
I get the same old:
[WARNING] Error reading archetype catalog http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
org.apache.maven.wagon.authorization.AuthorizationException: Access denied to: http://maven.mycompany.com/nexus/content/repositories/myrepo/archetype-catalog.xml
Any hints, or better documentation with working example?
To verify that you can now access to all archetypes, create a new maven project. Select new custom catalog you created. In first time, it will take a few moments to gather all the archetypes. You can see the progress at the very bottom right of the IDE.
How to Create an Archetype An archetype is a normal Maven project with the following extra content: To create an archetype manually, we can start with a newly created Maven project and then we can add the resources mentioned above.
How to create a master password. Use the following command line: mvn --encrypt-master-password <password>. Note: Since Maven 3.2.1 the password argument should no longer be used (see Tips below for more information). Maven will prompt for the password.
The maven-archetype-plugin allows the user to create a Maven project through the generate goal and existing archetype. For more information on this plugin, you can visit the homepage.
There's currently no way to do that if you don't specify at least -DarchetypeArtifactId
. As per the official docs you linked:
The server id used to download the artifact is [archetypeArtifactId]-repo
hence there's no way to just browse the catalog if it's password protected (and you're not willing to expose username/password on your shell history).
In the meanwhile, you can go ahead and vote for ARCHETYPE-204. They have a patch already available since years, they probably just need a bit of a push.
UPDATE
Looking into the source code of the maven archetype project, looks like the following snippet in the settings.xml
might work for you:
<servers>
<server>
<id>archetype</id>
<username>${your username}</username>
<password>${your password}</password>
</server>
</servers>
There is a default ID of archetype
when building the Repository
object while fetching a remote catalog. I don't think it's the official way of dealing with such situations, and it's a bit dirty IMO. But it might still work for you :-)
Also, you should be able to set profiles for reusing the archetype
ID for different servers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With