Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven archetype catalog : specify custom location(s)

I'm deploying a Nexus repository for Maven, and custom archetypes on it.

I would like to execute mvn archetype:generate and be prompted a list of internal + custom archetypes.

The only way I found to prompt custom archetypes (in an ergonomic way, meaning no URL) is to define the archetype-catalog path as a property in the settings. This is not a valid solution because I want several catalogs (and this property cannot be overriden in CLI).

Does anybody have a clue on how to do that ?

Thanks in advance,


[EDIT] I found an issue report related : http://jira.codehaus.org/browse/ARCHETYPE-273

And I noticed that during archetype:generate, maven tries to reach the central repository :

[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2/archetype-catalog.xml
[DEBUG] Searching for remote catalog: http://repo1.maven.org/maven2

It ends by a "Connection Timed out" because I did not (and don't want to) specify a proxy...

I don't understand why maven doesn't check nexus catalog...

like image 286
Benjamin Avatar asked Jul 06 '11 12:07

Benjamin


2 Answers

I also have a Nexus configured to mirror the Maven repositories and thus the remote catalog too.

<mirror>
    <!--This sends everything else to /public -->
    <id>nexus</id>
    <mirrorOf>*</mirrorOf>
    <url>http://afbwt03:8081/nexus/content/groups/JavaRepo/</url>
</mirror>

and:

<profile>
    <id>nexus</id>
    <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>

I am able to access the remote catalog only when I use the following Maven command line:

mvn archetype:generate -DarchetypeCatalog=http://afbwt03:8081/nexus/content/groups/JavaRepo

If I don't define the archetypeCatalog variable, I get the same behavior as you do: trying to access the repo1. ... although some mirrors are configured.

like image 60
leroyse Avatar answered Nov 16 '22 01:11

leroyse


You need to have

  • the property archetypeRepository defined in the active profile in your .m2/settings.xml

  • the repositories and pluginRepositories redirected to your mirror, on the same id "central".

  • and of course, the mirror defined

Apache maven documentation on archetype plugin specifies that archetypeRepository is definable user property: http://maven.apache.org/archetype/maven-archetype-plugin/generate-mojo.html

Your .m2/settings.xml should have these minimal elements

<?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">


  <mirrors>
      <mirror>
        <id>central</id>
        <name>Mirror for maven central</name>
        <url>http://mymvnhost:8081/nexus/content/groups/public/</url>
        <mirrorOf>*</mirrorOf>
      </mirror>

  </mirrors>

  <profiles>
    <profile>
      <id>dev</id>

        <properties>
        <archetypeRepository>http://mymvnhost:8081/nexus/content/groups/public/</archetypeRepository>
        </properties>

        <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>dev</activeProfile>
  </activeProfiles>
</settings>
like image 33
Blessed Geek Avatar answered Nov 16 '22 02:11

Blessed Geek