Search code examples
javamavenmaven-archetype

Archetype plugin error in "Maven in 5 Minutes" tutorial


I'm trying the Maven in 5 Minutes tutorial and running into an error almost immediately. The results from mvn --version are

Apache Maven 3.5.2
Maven home: /usr/share/maven
Java version: 1.8.0_171, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-23-generic", arch: "amd64", family: "unix"

When I run the next command in the tutorial,

$ mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app \
   -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

I get the following error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli)
on project standalone-pom: archetypeCatalog 'http://mavenrepo.openmrs.org/nexus/content/repositories/public/archetype-catalog.xml'
is not supported anymore. Please read the plugin documentation for details. -> [Help 1]

Where "Help 1" is just docs for MojoFailureException.

It seems like the archetype plugin released a breaking change and the Maven tutorial hasn't been updated to reflect that. Though, interestingly, the command suggested by the docs for the Quickstart Archetype,

$ mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.3

also fails with the same error.

Is it still possible to generate a maven project based on the Quickstart archetype, and if so, how do I do it?

EDIT: Here's my ~/.m2/settings.xml file:

<?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>${env.BINTRAY_USER}</username>
      <password>${env.BINTRAY_API_KEY}</password>
      <id>bintray-sdk</id>
    </server>
  </servers>
  <profiles>
    <profile>
      <properties>
        <archetypeRepository>http://mavenrepo.openmrs.org/nexus/content/repositories/public</archetypeRepository>
        <archetypeCatalog>http://mavenrepo.openmrs.org/nexus/content/repositories/public/archetype-catalog.xml</archetypeCatalog>
      </properties>
      <repositories>
        <repository>
          <id>openmrs-repo</id>
          <name>OpenMRS Nexus Repository</name>
          <url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
        </repository>
        <repository>
          <id>openmrs-repo-thirdparty</id>
          <name>OpenMRS Thirdparty Nexus Repository</name>
          <url>http://mavenrepo.openmrs.org/nexus/content/repositories/thirdparty</url>
        </repository>
        <repository>
          <id>openmrs-bintray-repo</id>
          <name>OpeMRS Maven Bintray Repository</name>
          <url>https://dl.bintray.com/openmrs/maven/</url>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
          <id>openmrs-repo</id>
          <name>OpenMRS Nexus Repository</name>
          <url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
        </pluginRepository>
        <pluginRepository>
          <id>openmrs-bintray-repo</id>
          <name>OpeMRS Maven Bintray Repository</name>
          <url>https://dl.bintray.com/openmrs/maven/</url>
        </pluginRepository>
      </pluginRepositories>
      <id>openmrs</id>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>openmrs</activeProfile>
  </activeProfiles>
  <pluginGroups>
    <pluginGroup>org.openmrs.maven.plugins</pluginGroup>
  </pluginGroups>
</settings>

Solution

  • Actually, using archetypeCatalog is deprecated as the error message suggests. You have to remove properties archetypeRepository and archetypeCatalog from your settings.xml, and declare a repository with archetype as id, like this :

    <settings>
        <profile>
            <id>openmrs</id>
            <repositories>
                <repository>
                    <id>archetype</id>
                    <url>http://mavenrepo.openmrs.org/nexus/content/repositories/public</url>
                </repository>
                <!-- keep other repositories -->
            </repositories>
        </profile>
    </settings>
    

    Your active profile is openmrs, so archetypes should be found using this configuration since they are present in the openmrs repository (see https://mavenrepo.openmrs.org/nexus/content/repositories/public/org/apache/maven/archetypes/).