Are there other default maven archetype properties -
i'm creating maven archetype has bunch of custom properties.
ex:
<requiredproperties> <requiredproperty key="db-name"> <defaultvalue>some db-name</defaultvalue> </requiredproperty> <requiredproperty key="station-name"> <defaultvalue>localhost</defaultvalue> </requiredproperty> ... </requiredproperties>
when new project generated based on archetype maven knows default variables groupid, artifactid, version. maven knows others trivial variables env.user, user, host, path, basedir or others? are? how can them?
thanks.
i realise old question, came across question earlier , voted it. wondering same, have come solution / workaround enabling access these properties.
i created own maven plugin aptly named property-setter-maven-plugin
sets system and, importantly, execution properties. configuration of plugin allows number of properties , values specified (and since defined in pom, have access of normal variables). when archetype plugin run (in same maven execution custom plugin), reads execution properties , finds have configured.
my maven command looks this:
mvn \ com.example.build.maven:property-setter-maven-plugin:0.1:set-properties \ archetype:generate \ -darchetypegroupid=... -darchetypeartifactid=... -darchetypeversion=... -dartifactid=...
the configuration in pom sits in same directory archetype generated looks this:
... <plugin> <groupid>com.example.build.maven</groupid> <artifactid>property-setter-maven-plugin</artifactid> <version>0.1</version> <executions> <execution> <goals><goal>set-properties</goal></goals> <configuration> <version>${project.version}</version> <username>${user.name}</username> </configuration> </execution> </executions> </plugin> ...
the plugin code, modified set system properties below:
package com.example.build.maven.mojo; import org.apache.maven.execution.mavensession; import org.apache.maven.model.plugin; import org.apache.maven.model.pluginexecution; import org.apache.maven.plugin.abstractmojo; import org.apache.maven.plugin.mojoexecution; import org.apache.maven.plugin.mojoexecutionexception; import org.apache.maven.plugin.mojofailureexception; import org.apache.maven.project.mavenproject; import org.codehaus.plexus.util.xml.xpp3dom; import java.util.properties; /** * propertysettermojo * * @goal set-properties * @phase validate * @since 0.1 */ public class propertysettermojo extends abstractmojo { /** * @parameter default-value="${project}" * @parameter required * @readonly */ private mavenproject project; /** * @parameter expression="${session}" * @readonly */ private mavensession session; /** * @parameter expression="${mojoexecution}" * @readonly * @required */ protected mojoexecution execution; /** * */ @override public void execute() throws mojoexecutionexception, mojofailureexception { try { plugin plugin = execution.getplugin(); string executionid = execution.getexecutionid(); pluginexecution pluginexecution = plugin.getexecutionsasmap().get(executionid); xpp3dom config = ((xpp3dom) pluginexecution.getconfiguration()); properties executionproperties = session.getexecutionproperties(); (int = 0; < config.getchildcount(); i++) { xpp3dom configentry = config.getchild(i); string propertyname = configentry.getname(); string propertyvalue = configentry.getvalue(); system.setproperty(propertyname, propertyvalue); executionproperties.setproperty(propertyname, propertyvalue); getlog().info("set system , execution property: " + propertyname + " => " + propertyvalue); } } catch (exception e) { throw new mojoexecutionexception("failed set properties", e); } } }
Comments
Post a Comment