maven archetype assembly failure on dashclassifier - maven

i have a archetype project which has a assembly.xml inside archetype-resources. it all worked fine till i had to change this
<unpack>false</unpack>
<outputFileNameMapping>${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping>
in <dependencyset>.
For some reason the clean install gives an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.1:integration-
test (default-integration-test) on project jetxyz:
[ERROR] Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Encountered "?}." at line 15, column 110 of archetype-resources/assembly.xml
[ERROR] Was expecting one of:
[ERROR] "}" ...
[ERROR] <DOT> ...
when I use the same changes on an actual project assembly.xml this complies fine, gives issue only in the archetype project. Which is strange. I was expecting Maven to not worry about archetype-resources at all.
edit
default value of outputFileNameMapping is ${artifact.artifactId}-${artifact.version}${dashClassifier?}.${artifact.extension} . All I did was change version to baseVersion. dependencySet

Related

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

maven-compiler-plugin compile project with jar library

I have a maven project, which has a library (hello1.jar), that I add with IDEA. In this jar file I have the class ru.training.Hello1. In project I have the class Hello2, which contains field Hello1 hello1. When I try to compile the project with maven lifecycle, I get an error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project Learning: Compilation failure: Compilation failure:
[ERROR] /C:/Projects/Learning/src/main/java/reflection/Hello2.java:[3,19] package ru.training does not exist
[ERROR] /C:/Projects/Learning/src/main/java/reflection/Hello2.java:[7,13] cannot find symbol
[ERROR] symbol: class Hello1
What can I do to fix this error?
In this case you need to add local jar file to local repository and then compile the project. How to add local jar I have read here: How to add local jar files to a Maven project?

Can I use a custom lifecycle defined in a multi-module project?

I have a project that has a complex lifecycle, so a custom lifecycle makes sense. However, I would like to be able to have the lifecycle defined in a plugin that is in the same multi-module build. The plugin just defines the custom lifecycle (in a components.xml).
apollo-server-parent
- apollo-server-lifecycle-plugin
- src/main/resources/META-INF/plexus/components.xml (defines apollo-server-product)
- ApolloServer
- pom.xml
...
<packaging>apollo-server-product</packaging>
...
<plugin>
<groupId>ca.nanometrics.apollo</groupId>
<artifactId>apollo-server-lifecycle-plugin</artifactId>
<version>${project.parent.version}</version>
<extensions>true</extensions>
</plugin>
However, if I do this, maven won't build because it cannot find the apollo-server-lifecycle-plugin because it has not been built yet while building the reactor. Any ideas on how to work around this? Do I have to define the plugin in a separate project?
An example of the error I get:
[ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable build extension: Plugin ca.nanometrics.apollo:apollo-server-plugin:4.0.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact ca.nanometrics.apollo:apollo-server-plugin:jar:4.0.0-SNAPSHOT in releases (http://.../nexus/content/groups/public) #
[ERROR] Unknown packaging: apollo-server-product # ca.nanometrics.apollo:ApolloServer:[unknown-version], /opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml, line 10, column 14
#
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR] The project ca.nanometrics.apollo:ApolloServer:4.0.0-SNAPSHOT (/opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml) has 2 errors
[ERROR] Unresolveable build extension: Plugin ca.nanometrics.apollo:apollo-server-plugin:4.0.0-SNAPSHOT or one of its dependencies could not be resolved: Could not find artifact ca.nanometrics.apollo:apollo-server-plugin:jar:4.0.0-SNAPSHOT in releases (http://.../nexus/content/groups/public) -> [Help 2]
[ERROR] Unknown packaging: apollo-server-product # ca.nanometrics.apollo:ApolloServer:[unknown-version], /opt/atlassian/pipelines/agent/build/ApolloServer/pom.xml, line 10, column 14
If I am not getting you wrong here -
You want to build ApolloServer module, which uses
apollo-server-lifecycle-plugin which is also a module of your
project.
Current project structure being :
apollo-server-parent
- apollo-server-lifecycle-plugin
- ApolloServer
From the multi-module guide, one simple way of doing this could be making sure that apollo-server-lifecycle-plugin is build prior to the ApolloServer module always. Easiest way to do that could be to include the dependency of apollo-server-lifecycle-plugin in ApolloServer(pom.xml) which would make sure the Reactor sorting builds plugin first.
a plugin dependency on another module in the build

Maven build using Jenkins

I created a job to build the maven project, by configuring Jenkins as per standard conventions like:
svn repository URl: valid link
Under Build section:-
root pom: location of pom.xml file
goals and options: clean install
saved and started build
got console output as :
Parsing POMs ERROR: Failed to parse POMs
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[WARNING] 'version' contains an expression but should be a constant. # line 8, column 11
where line 8 is:
<version>${dsstextversion}</version>
if it is asking for version no., then how to invoke version no. into this ?

Maven says archetype does not exist

I am trying to create a JPA based project using Maven and eclipse. I tried using the jpa-maven-archetype from create new maven project in the eclipse project creation, but it shot back this error
Could not resolve archetype com.rfc.maven.archetypes:jpa-maven-archetype:RELEASE from any of the configured repositories.
Could not resolve artifact com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Failed to resolve version for com.rfc.maven.archetypes:jpa-maven-archetype:pom:RELEASE: Could not find metadata com.rfc.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
Basically the eclipse plugin is looking into my local repositories instead of remote ones. So I tried going the command line and explicitly specifying the remote repository with the following command
mvn org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create \
-DgroupId=com.something -DartifactId=jpaexample \
-DarchetypeArtifactId=jpa-maven-archetype \
-DarchetypeVersion=RELEASE \
-DremoteRepositories=http://maven.rodcoffin.com/repo \
-DinteractiveMode=false
And I got this error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:1.0-alpha-7:create (default-cli) on project standalone-pom: Error creating from archetype: Error attempting to download archetype. Error downloading. Failed to resolve version for org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE: Could not find metadata org.apache.maven.archetypes:jpa-maven-archetype/maven-metadata.xml in local (/home/sebastian/.m2/repository)
[ERROR] org.apache.maven.archetypes:jpa-maven-archetype:jar:RELEASE
[ERROR]
[ERROR] from the specified remote repositories:
[ERROR] id0 (http://maven.rodcoffin.com/repo, releases=true, snapshots=true)
[ERROR] -> [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
It seems that repo maven.rodcoffin.com/repo is not working, or there is something wrong with my maven setup. I am not sure which one, if some one could give me pointers on where to search for, that would be helpful.
Also if repo maven.rodcoffin.com/repo is not working. What are my other options to create a JPA archetype project. Do I have to make a simple maven project and then convert it to a JPA as shown here.
EDIT: I just weaseled out of the problem by creating a maven quick type achetype and then using the persistence.xml for my project.
So just ignore this question.

Resources