"Error reading POM" when selecting a archetype in Maven setup - maven

I downloaded maven 3.0.3, set-up my environment variables as instructed and verified with mvn --version that everything looks ok. So far so good
So, time to RTFM.. about 1 minute into the manual, weirdness occurs.
mvn archetype:generate \
-DarchetypeGroupId=org.apache.maven.archetypes \
-DgroupId=com.mycompany.app \
-DartifactId=my-app
It asked me to select a archetype from this long list, I took the quickstart one 135.
However, this doesn't work.. it spits out the following error:
[ERROR] Failed to execute goal
org.apache.maven.plugins:maven-archetype-plugin:2.1:generate
(default-cli) on project standalone-pom: Error reading POM -> [Help 1]
What am I doing wrong?

Up-to-date documentation: the free book by Sonatype. I learned some stuff from there even after using Maven for over 3 years.

Related

Could not find artifact org.apache.pulsar:pulsar-broker:pom:2.12.0-SNAPSHOT in apache.snapshots (https://repository.apache.org/snapshots)

While following the instructions to setup IntelliJ for pulsar development I got the below error
Could not find artifact org.apache.pulsar:pulsar-broker:pom:2.12.0-SNAPSHOT in apache.snapshots (https://repository.apache.org/snapshots)
Digging deeper into the snapshots, I don't see pulsar-broker at 2.12.0 either: https://repository.apache.org/content/groups/snapshots/org/apache/pulsar/pulsar-broker/
Is there some configuration step missing?
Attempted Fix [RESOLVED]
accepted answers steps and fix an issue with SDKMAN to have mvn call Java 17
I tried the command mvn -Pcore-modules,-main clean install -DskipTests -Dspotbugs.skip=true and got the new error below.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project buildtools: Compilation failure
[ERROR] /Users/brandon.hoffman/Projects/pulsar/buildtools/src/main/java/org/apache/pulsar/tests/RetryAnalyzer.java:[30,18] cannot access org.testng.ITestResult
[ERROR] bad class file: /Users/brandon.hoffman/.m2/repository/org/testng/testng/7.7.0/testng-7.7.0.jar(org/testng/ITestResult.class)
[ERROR] class file has wrong version 55.0, should be 52.0
[ERROR] Please remove or make sure it appears in the correct subdirectory of the classpath.
Running this on the command line will fix that problem:
mvn -Pcore-modules,-main clean install -DskipTests -Dspotbugs.skip=true
You must use Java 17 for compiling the master branch version of Pulsar (requirements).
It's possible that there has been some change in the maven build after the instructions were originally written.
It does not look like the project is currently using the repository.apache.org for nightly snapshots. You should ask your question on the dev#pulsar.apache.org mailing list.
Also we have not yet cut the 2.12 branch. The VOTE for the first release of 2.11.0 just passed the PMC.
(FYI I am an Apache Pulsar PMC Member)

I want to upload a JAR to a GitLab package registry

I have a prebuilt JAR file that I want to upload into a GitLab package registry so it can be using when a build is performed.
This is my first time playing with Maven and uploading so newbie alert here!
In my project in GitLab I do see that there is a section titled "package registry". I assume that I need to upload it there.
I found the following command which I thought might do the trick:
mvn deploy:deploy-file -DgroupId=com.acme.group -DartifactId=project-name \
-Dversion=1.2.3 -Dpackaging=jar -Dfile="test.jar" \
-Durl=https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages
-DrepositoryId=project-name
I have no idea what to put in for "DrepositoryId", "DartifactId". The other field I assumed in what i put.
How do I know what to put in those fields?
I run it and get the following :
Uploading to remote-repository: https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.793 s
[INFO] Finished at: 2021-06-01T15:51:09-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.acme.group:project-name:jar:1.2.3 from/to remote-repository (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages): transfer failed for https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.jar, status: 422 Unprocessable Entity -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
vanduyne-16mb:ernie-sandbox-1 vanduyer$ -DrepositoryId=project-name
bash: -DrepositoryId=project-name: command not found
Perhaps I need to allow permissions to upload to that location in GitLab - which I have no clue how to do.
Is that even where I should upload it to?
I have tried looking at the Maven sites and other sites for help on how to do this but I can not find something explaining this for a newbie.
Thanks for any help!
There are a few problems that I will list below.
First of all, you are missing a \ at the end of the third line. So, the -DrepositoryId=project-name parameter is not passing to the mvn deploy command.
Next, you need to decide which level do you want to deploy the artifact? You can read more about the levels on Gitlab's official documentation (GitLab endpoint for Maven packages). These addresses lead to /packages/maven, but you are missing the /maven token in the URL. (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages)
You don't need to pass a repositoryId if you didn't configure any server inside your settings.xml file. If you configured it, then you can use the defined Id. So, Maven can use the configuration from the settings.xml file. You can read more about the repositoryId on Maven's official documentation: repositoryId
The groupId and artifactId parameters are the required parameters that define how you can import the artifact from the repository. I suggest you use the same groupId and the artifactId configured inside the pom.xml file of the artifact. If you deploy a package with groupId=com.group and artifactId=artifact-id then you can import the artifact to your project like this:
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>artifact-id</artifactId>
<version>...</version>
</dependency>
...
</dependencies>
I suggest read more about deploying to Gitlab's Maven repository since you have to configure the authentication section as well: Maven packages in the Package Repository

Using OpenDaylight starter archetype does not work

Trying to follow the opendaylight developer tutorial to get an initial hello world application running on the controller, however running the command
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype \ -DarchetypeRepository=https://nexus.opendaylight.org/content/repositories/public/ \ -DarchetypeCatalog=https://nexus.opendaylight.org/content/repositories/public/archetype-catalog.xml
Results in an error
No plugin found for prefix ' -DarchetypeRepository=https' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (/home/andrew/.m2/repository), opendaylight-snapshot (https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/), opendaylight-mirror (https://nexus.opendaylight.org/content/repositories/public/), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
I've managed to get it to succeed using the command
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default) on project test-impl: You have 1 Checkstyle violation. -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (default) on project test-impl: You have 1 Checkstyle violation. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
Any ideas how to resolve this (or other ways of getting a first app)?
From this link, you can use the following command :
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype \
-DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/<Snapshot-Type>/ \
-DarchetypeCatalog=remote -DarchetypeVersion=<Archetype-Version>
while replacing Snapshot-Type and Archetype-Version as follows:
Using this search on ODL's Nexus repository:
For the Oxygen dev snapshot use Snapshot-Type=opendaylight.snapshot and Archetype-Version=1.5.0-SNAPSHOT
For the Nitrogen SR1 snapshot use Snapshot-Type=opendaylight.snapshot and Archetype-Version=1.4.1-SNAPSHOT
For the Nitrogen release use Snapshot-Type=opendaylight.release and Archetype-Version=1.4.0
For the Carbon use Snapshot-Type=opendaylight.release and Archetype-Version=1.3.0-Carbon
For Boron SR0 use Snapshot-Type=opendaylight.release and Archetype-Version=1.2.0-Boron
For Boron SR1 use Snapshot-Type=opendaylight.release and Archetype-Version=1.2.1-Boron-SR1
For Boron SR2 use Snapshot-Type=opendaylight.release and Archetype-Version=1.2.2-Boron-SR2
For the Boron snapshot use Snapshot-Type=opendaylight.snapshot and Archetype-Version=1.2.2-SNAPSHOT
You can also see this answer.
I have found a solution in the OpenDaylight forum.
Please remove
-DarchtypeCatlog=http://nexus.opendaylight.org/content/repositories/opendaylight.release/archetype-catalog.xml
and execute following command.
mvn archetype:generate -DarchetypeGroupId=org.opendaylight.controller -DarchetypeArtifactId=opendaylight-startup-archetype -DarchetypeRepository=http://nexus.opendaylight.org/content/repositories/opendaylight.release -DarchetypeVersion=1.4.0

Logging error when executing Maven SonarQube plugin

I've been facing an issue with Maven SonarQube plugin (v2.6) when Maven version is recent (strictly larger than 3.1).
Here is what I run:
mvn clean verify -Psonar
mvn org.codehaus.mojo:sonar-maven-plugin:2.6:sonar -Psonar
The first invocation makes sure sources are compiled and JaCoCo agent is prepared.
The interesting part comes, when the second command is run:
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project merlin-schema: Error setting Log implementation. Cause: java.lang.reflect.InvocationTargetException: org/slf4j/Marker -> [Help 1]
Any fix to be published?
Replacing default Maven logging implementation is currently not supported. Ticket created: http://jira.sonarsource.com/browse/MSONAR-122

maven error: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT)

I am trying to create php project using maven by tying below command:
sudo mvn archetype:generate -DarchetypeGroupId=org.phpmaven
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0-SNAPSHOT
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
but it gives me error:
Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli)
on project standalone-pom: The desired archetype does not exist (org.phpmaven:php5-web-archetype:2.0-SNAPSHOT) -> [Help 1]
Apparently you're trying to follow these instructions. If you do, you should also do the preparation steps that have been listed.
Doing that you're relying on a snapshot archetype, and those do not exist in default repositories, so you have to configure php-maven snapshot repository.
After doing that,
Confirm your settings.xml location (in the comments you indicated you had that in the wrong folder)
try with
mvn archetype:generate -DarchetypeGroupId=org.phpmaven.sites
-DarchetypeArtifactId=php5-web-archetype -DarchetypeVersion=2.0.0-beta-1
-DgroupId=org.sample -DartifactId=my-app -Dversion=0.0.1-SNAPSHOT
Since you can see from the repo that that archetype version should be in place. Note the different archetypeversion and different archetypegroupid!

Resources