Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use property -Dgoal of archetype maven plugin. In this property you can specify additional goals to immediately run on the project created from the archetype.</p> <p>So, I create a new maven plugin module in my maven archetype project and this module contains all additional java logic that I want to be executed. I need not specify this plugin in newly created pom.xml of the generated project.</p> <p>More details: here is pom.xml of maven-plugin:</p> <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;yourGroupId&lt;/groupId&gt; &lt;artifactId&gt;init-maven-plugin&lt;/artifactId&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;packaging&gt;maven-plugin&lt;/packaging&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven&lt;/groupId&gt; &lt;artifactId&gt;maven-plugin-api&lt;/artifactId&gt; &lt;version&gt;3.0.4&lt;/version&gt; &lt;/dependency&gt; &lt;dependency&gt; &lt;groupId&gt;org.apache.maven&lt;/groupId&gt; &lt;artifactId&gt;maven-project&lt;/artifactId&gt; &lt;version&gt;3.0-alpha-2&lt;/version&gt; &lt;/dependency&gt; &lt;/dependencies&gt; </code></pre> <p></p> <p>And here is the Mojo:</p> <pre class="lang-java prettyprint-override"><code>/** * @goal maven-plugin-init */ public class InitMojo extends AbstractMojo { /** * @parameter expression="${project.basedir}" */ private File basedir; public void execute() throws MojoExecutionException, MojoFailureException { //write initialization logic here } } </code></pre> <p>So, in the "basedir" will be the basedir of the newly created project.</p> <p>The only issue is how to pass input parameters of our archetype to our initialization plugin. I just create using archetype a file "initial.properties" in the root of the newly created project and store there all input parameters. And then read this file in initialization plugin.</p> <p>To launch your archetype use following command: <code>mvn archetype:generate $archetype_properties -Dgoals=yourGroupId:init-maven-plugin:maven-plugin-init</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload