How can I combine library code and maven plugin in the same project?
Is it possible to create a single maven project that can be included as a dependency (for referencing the Java classes inside) and executed as a plugin?
I am working on a library to help with placing GWT on the LAMP stack. In order for someone to use this, they need to extend some Java classes (so it must be a dependency) and they need to call the maven plugin (so it must be a plugin). The plugin code references the same Java classes, so if they are separate projects, the plugin must depend on the library.
As it 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 in order to execute a release, I must release two different artifacts, and the dependent project must update both version numbers for both artifacts. It would be nice to have one project.
a source to share
You will be better off doing the following
- the project for the flag, Foo: Foo.jar
- which uses Foo: Foo.jar as a dependency that builds the plugin
- parent Maven project that builds 1 & 2
The directory structure will 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 mvn clean package
to build \project\foo\target\foo.jar
and\project\plugin\target\plugin.jar
Hope it helps.
a source to share
If you create a maven plugin, it still has an artifactId / groupId / file. There is no reason why it cannot be links in both your section and your section. On the other hand, if it's ugly, why not just create a shared code library that your main project and your maven plugin project depend on?
EDIT:
Sorry, the second part was not clear. Have a look at maven compound projects where the top level pom is located which determines the number of child modules. In this case, maven plugin and shared library code can 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 many open source projects out there. it is often used as an idiom to put test code in one module that everyone else can reference, without going out to any redistributable jar.
a source to share
The best practice is not to do what you suggest. Examples of this include PMD, BND, JUnit / TestNG, etc. - no serious projects seem to package the maven plugin with the library itself.
One way to get both alternatives is to use maven assemblies to create two separate maven projects for each library proper as well as the plugin and then packaged separately as a jar containing classes from both.
a source to share