views:

247

answers:

3

Can I make a single maven project that can be included as a dependency (to reference Java classes inside) and executed as a plugin?

I'm working on a library to help with hosting GWT on a LAMP stack. For someone to use this, they need to extend some Java classes (so it must be a dependency) and they need to invoke a maven plugin (so it needs to be a plugin). The plugin code references the same Java classes, so if they are seperate projects, the plugin one must depend on the library one.

As is, I have the library as a normal maven project, and the plugin as a maven plugin that depends on the library. This means that to do a release, I have to release two different artifacts, and the dependent project must update both version numbers for both artifacts. It'd be nice to have a single project.

+1  A: 

If you create a maven plugin it still has a artifactId/groupId/version. There's no reason it can't be references both in your section and in your section. On the other hand, if thats ugly, why not just make a library with the common code that both your main project and your maven plugin project depend on?

EDIT:

Sorry, wasn't clear on the second part. Look into composite maven projects, where there is a top level pom that defines a number of child modules. In this case, the maven plugin and the common library code could be separate children producing separate artifacts, but you only need one version number and one release command executed from the top level. I haven't done this but there are any number of open source projects that do. its often used as an idiom to put testing code into a single module that can be referenced by all the others, without having it go out in any distributable jar.

Jherico
I agree on the putting common code in a separate project rather than the ugly build/self reference. For one thing, it guarantees that you will always have a circular reference.
sal
+1  A: 

You'd be better of by doing the following

  1. project for the jar, Foo:Foo.jar
  2. project that uses Foo:Foo.jar as a dependency that builds the plugin
  3. Maven parent project that builds 1&2

The directory structure would look like this

\project\pom.xml
\project\foo\pom.xml
\project\foo\src\main\java\foo.java
\project\plugin\pom.xml
\project\plugin\src\main\resources
\project\plugin\src\main\java

From \project you can do a mvn clean package to build \project\foo\target\foo.jar and \project\plugin\target\plugin.jar

Hope this helps.

sal
A: 

The best practice is to not do what you're suggesting. Examples of this include PMD, BND, JUnit/TestNG, and so on - no serious projects seem to package the maven plugin with the library proper.

One way to get both alternatives is to use maven assemblies to have two seperate maven projects for each the library proper and the plugin and then a separate packaging as a jar containing the classes from both.

James Kingsbery