0

Is it possible to combine the capabilities of an archetype and a normal Maven plugin into a single plugin?

I have a custom language which I can compile into Java source code. I've written a Maven plugin which does this in the generate-sources phase, adds the Java source to the project, and builds the project. It works as I'd expect.

However, to use it, I need to first write out a pom.xml file referencing my plugin and describing where the input files live. I'd like to be able to go straight from raw input files to compiled code in a single maven command.

For example, suppose I have this directory structure:

my-project/ some-input-file.dsl 

I want to run

bash$ mvn com.waisbrot.plugin:generate -DgroupID=com.waisbrot package 

and after Maven's done running have:

my-project/ some-input-file.dsl pom.xml target/ generated-sources/ plugin/ SomeInputFile.java classes/ com/ waisbrot/ SomeInputFile.class some-input-file-1.0.jar 
2
  • The best thing is to configure your plugin into the lifecycle within the pom you've shown. That's it. The location of your dsl file should be changed like src/main/name-of-your-dsl/xyz-input-file.dsl. Like other DSL are handled with Maven like Groovy etc. Commented Jan 12, 2013 at 18:53
  • The file could be moved and its new location stored in the generated POM; I don't care about that. What I'm asking is if I can transform a non-Maven directory into a Maven project and then in the same breath execute a maven goal on that newly-created project. Commented Jan 13, 2013 at 10:16

1 Answer 1

1

Actually, the integration testing of the archetype allows you to declare the parameter and goals. So do this:

  1. Pick the template project you want to create
  2. mvn archetype:create-from-project. It will create a new archetype
  3. Review src/test/resources/projects, especially goal.txt and archetype.properties (source: http://maven.apache.org/archetype/maven-archetype-plugin/integration-test-mojo.html). Tweak so install will be implicity
  4. mvn verify will be able to build the archetype, run the it, and get it installed

Hope it helps

Sign up to request clarification or add additional context in comments.

2 Comments

Well it appears that I'm asking for something totally unsupported by Maven. This is probably the closest I'll be able to get and looks like a pretty nifty kludge. Thanks!
It helps if you split your functionality into several @Mojos, each one by default bound to a lifecycle phase.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.