I'm trying to generate custom maven archtype, I'm trying below example to generate custom maven spring boot archtype:
Custom Maven Archtype
If I try to run the below maven generate command - works good
mvn archetype:generate \
-DarchetypeGroupId=com.romeh.spring-boot-archetypes \
-DarchetypeArtifactId=spring-boot-quickstart \
-DarchetypeVersion=1.0.0 \
-DgroupId=com.test \
-DartifactId=sampleapp \
-Dversion=1.0.0-SNAPSHOT \
-DinteractiveMode=false
But if I change the Group ID with my custom name - it started failing
For example if I change this from -DarchetypeGroupId=com.romeh.spring-boot-archetypes to -DarchetypeGroupId=com.test.spring-boot-archetypes
I'm getting below error message - if I change the group id.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:26 min
[INFO] Finished at: 2018-04-19T11:45:36-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:3.0.1:generate (default-cli) on project spring-boot-quickstart: The desired archetype does not exist (com.test.spring-boot-archetypes:spring-boot-quickstart:1.0.0) -> [Help 1]
Please note that - before executing this command I've changed group id in pom.xml and archetype-catalog.xml as well.
Can you please help me to fix this issue - not sure what i'm doing wrong here.
You just should not do that. These properties
-DarchetypeGroupId=com.romeh.spring-boot-archetypes
-DarchetypeArtifactId=spring-boot-quickstart
-DarchetypeVersion=1.0.0
identifies the archetype; it's like when you have some JAR and you want to add it to your project you need to provide groupId, artifactId and version.
The same approach is used for archetypes! Archetypes are packaged up in a JAR and they consist of the archetype metadata which describes the contents of the archetype.
Those properties say Maven what archetype (like what JAR) it should run to generate your app skeleton. And if you change them - Maven won't just find the appropriate JAR in the repository.
Instead, you should modify:
-DgroupId=com.test
-DartifactId=sampleapp
-Dversion=1.0.0-SNAPSHOT
Those will be properties of your project generated by that archetype.
Related
I have the following command, which I'm using to build a specific microservice (<ms-name>):
./mvnw -DskipTests clean install -pl <ms-name> -am
clean, instal, and -DskipTest are clear. But I don't understand what -pl and -am are doing.
logs:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] <utils-1> [jar]
[INFO] <utils-2> [jar]
[INFO] <ms-name> [jar]
and after it starts executing clean install on , , and in the end <ms-name>
I have checked the pom.xml but could not see the relations somewhere.
My question is: What are -pl and -am and where I can find this 'order' building relation between <ms-name>, <utils-1>, and <utils-2>?
From documentation,
-pl is,
Comma-delimited list of specified reactor projects to build instead of
all projects. A project can be specified by [groupId]:artifactId or
by its relative path
-am is,
If project list is specified, also build projects required by the list
where I can find this 'order' building relation ..?
It is handled by reactor (and internal program within maven) which collects all the available modules to build, sorts the projects into the correct build order and builds the selected projects in order.
To get understand more about maven reactor, here is a StackOverflow answer which is more detailed enough.
What is the "reactor" in Maven?
In Jenkins, I have a Maven project with the following structure:
x proftaakmaven
- AutosimulatieSysteem
- LandenMonitoringSysteem
- PolitieSysteem
x Verplaatsingssysteem
- VerplaatsingREST
- VerplaatsingSOAP
- VerplaatsingCommon
- VerplaatsingenRabbitMQ
- RabbitMQ-Proof-of-Concept
- VerplaatsingenRabbitMQTestClient
The Maven reactor constructs this building order:
[INFO] Reactor Build Order:
[INFO]
[INFO] AutoSimulatie
[INFO] LandenMonitorSysteem
[INFO] PolitieSysteem
[INFO] VerplaatsingenSysteem
[INFO] VerplaatsingenCommon
[INFO] VerplaatsingenREST
[INFO] VerplaatsingenSOAP
[INFO] RabbitMQ-Proof-of-Concept
[INFO] VerplaatsingenRabbitMQ
[INFO] VerplaatsingenRabbitMQTestClient
[INFO] proftaakmaven
However, due to a current failure in 'LandenMonitorSysteem' source code, Maven fails on building the other modules as well. This makes the Jenkins job fail.
I have tried running Maven with --fail-never and --fail-at-end. But neither seem to have any effect.
How would I be able to continue building all the modules, even if one fails?
Thanks.
--fail-at-end should be the thing to use.
If that doesn't work you could use -pl to specify the list of working projects.
If you use the -am flag as well you can specify the target you are interested in building and Maven will calculate the dependency tree for you.
I.E. mvn clean install -pl VerplaatsingenRabbitMQTestClient -am
I have found the solution. The problem was the way that I provided the argument. In Jenkins 2.0, the job should be configured like this :
The settings inside the job
I am trying to understand what mvn clean:clean actually does.
mvn -B help:describe -Dcmd=clean
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building sample-one 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) # sample-one ---
[INFO] 'clean' is a lifecycle with the following phases:
* pre-clean: Not defined
* clean: org.apache.maven.plugins:maven-clean-plugin:2.5:clean
* post-clean: Not defined
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.689 s
[INFO] Finished at: 2015-12-10T10:20:16-08:00
[INFO] Final Memory: 9M/245M
[INFO] ------------------------------------------------------------------------
It appears to me that mvn clean:clean is same as doing mvn org.apache.maven.plugins:maven-clean-plugin:2.5:clean. Therefore I am assuming the first clean in mvn clean:clean is just an alias for org.apache.maven.plugins:maven-clean-plugin:2.5. Similarly mvn maven-surefire-plugin:2.12.4:test is same as mvn surefire:test.
So somehow, maven-surefire-plugin:2.12.4 seems to refer to surefire and org.apache.maven.plugins:maven-clean-plugin:2.5 to clean.
When I look at the effective-pom, I see the following
maven-surefire-plugin
2.12.4
default-test
test
test
maven-clean-plugin
2.5
default-clean
clean
clean
As you can see, the pom doesnt seem to define alias. So following are my questions
Is my understanding about plugin aliases correct
If my understanding about aliases is correct - a) how and where are they defined? b) Is there a way to list all aliases.
From official Maven documentation about plugins development:
Shortening the Command Line
There are several ways to reduce the amount of required typing:
If you need to run the latest version of a plugin installed in your local repository, you can omit its version number. So just use mvn sample.plugin:hello-maven-plugin:sayhi to run your plugin.
You can assign a shortened prefix to your plugin, such as mvn hello:sayhi. This is done automatically if you follow the convention of using ${prefix}-maven-plugin (or maven-${prefix}-plugin if the plugin is part of the Apache Maven project). You may also assign one through additional configuration - for more information see Introduction to Plugin Prefix Mapping.
Finally, you can also add your plugin's groupId to the list of groupIds searched by default. To do this, you need to add the following to your ${user.home}/.m2/settings.xml file:
<pluginGroups>
<pluginGroup>sample.plugin</pluginGroup>
</pluginGroups>
At this point, you can run the mojo with mvn hello:sayhi.
So, alias are not defined in the pom file but part of built-in mechanism of maven. Further details are also provided in the official documentation about Plugin Prefix Resolution.
I am trying to build and run a Spring MVC beginner lesson project using IntelliJ. I imported the existing project from GitHub. But when I try to build the project I keep getting:
Error:(3, 38) java: package org.springframework.stereotype does not exist
Error:(4, 47) java: package org.springframework.web.bind.annotation does not exist
These external dependencies jars are under my Maven local repositories (C:\Users\sudi.m2)and I can see in IntelliJ under Maven->Repositories that repo location is indeed there. I also tried "Invalidate Cache and restart" but that does not help. My M2_HOME is set correctly to C:\apache-maven-3.2.2. If I try to run mvn install from command line, I get:
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 40.845 s
[INFO] Finished at: 2014-09-25T19:03:21+05:30
[INFO] Final Memory: 9M/93M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project basic-web-app: Error assembling WAR: webxml attribute is required (or preexisting WEB-INF/web.xml if executing in update mode) -> [Help 1]
Any suggestions are appreciated.
If the project doesn't have a web.xml file (IE: Entirely java config based). The build war plugin will fail unless you specify the "failOnMissingWebXml" attribute to false.
Delete you local .m2 repository and let it re-download all needed jars. Maybe, there were issues while downloading one of the dependencies.
I'm trying to assemble a project using maven and the OpenImaj library, I been following the instructions on this page http://www.openimaj.org/tutorial/getting-started-with-openimaj-using-maven.html but some of the process seems to be different from the one outline in the tutorial, I have tried this on two different computers (mac and pc) and received the following errors/steps, any idea of where/what I am doing wrong will be helpful.
after running the mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate line I am prompt to "Choose a number or apply filter" where the default is 284.
Once I select 284 (should I be selecting anything else?), I'm being prompt to select "maven-archetype-quickstart version" where I choose the latest 6:1.1, following by the groupId, artifactId, version, package, and Y confirmation, this result with 'Build Success' and create the directory as well as the pom.xml file on my computer.
When I navigate to the project folder "cd projectName" and run the mvn assembly:assembly command, I first see that a few of the packages are being collected, then I see a "Build Failure" notification -"Failed to execute goal org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5.... No assembly descriptors found.
any idea what I am doing wrong and how I can get the OpenImaj lib integrated into a project, should I be downloading the SVN version and attempt to set the projects from local libraries.
Many thanks in advance!
Just add this plugin to your pom.xml. This solved the problem for me:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
Are you sure you're entering the maven command in step 1 correctly? You should only see three options (just confirmed this is working on both OSX, debian & ubuntu):
abe:~ jon$ mvn -DarchetypeCatalog=http://maven.openimaj.org/archetype-catalog.xml archetype:generate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:2.2:generate (default-cli) # standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: http://maven.openimaj.org/archetype-catalog.xml -> org.apache.maven.archetypes:maven- archetype-quickstart (An archetype which contains a sample Maven project.)
2: http://maven.openimaj.org/archetype-catalog.xml -> org.openimaj:openimaj-quickstart-archetype (Maven quickstart archetype for OpenIMAJ)
3: http://maven.openimaj.org/archetype-catalog.xml -> org.openimaj:openimaj-subproject-archetype (Maven archetype for creating OpenIMAJ subprojects with the most of the standard configuration completed automatically)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains):
You then need to pick the org.openimaj:openimaj-quickstart-archetype option from the list (probably #2).
I had faced similar issues and finally worked it out. There are two things to note here. One is the network we are using and second is the maven tool we are using.
In your eclipse IDE go to window -> preferences.
Under maven tab go to installations sub-tab. Instead of using the embedded maven add filepath to maven installed on your system (The one command Line uses).
Under General Tab go to Network connections tab. Change the active provider.
Neither of the above will completly build the project successfully in one go. But each combination of network and maven will download some jars. Once you try two to three combinations you will have all the jars and the project will build successfully.