My project requires using custom Maven plugin, and I am looking for simple way to build it, preferably without messing local repository.
Let's consider simple projects tree:
root-project
|---pom.xml
|---my-library
| \---pom.xml
|---my-maven-plugin
| \---pom.xml
\---my-project
\---pom.xml
root-project
has three subprojects listed as <modules>
inside. The main thing is that my-project
uses my-maven-plugin
during it's build process, so the plugin must be built first.
What I would like to do, is to simply run:
root-project $ mvn package
This should build my-maven-plugin
first and use it during build of my-project
.
Unfortunately, this does not work. Maven stops working during "scanning for projects..." phase, with error message:
Unresolveable build extension: Plugin test:my-maven-plugin:1.0 or one of its dependencies could not be resolved: Could not find artifact test:my-maven-plugin:jar:1.0
It works if I do first
$ cd my-maven-plugin
$ mvn install
$ cd ..
$ mvn package
It does not look good. However, real problem is that the plugin depends itself on my-library
(which is another child module of root). So, before building plugin I must enter library directory and install it. Things become worse and worse with every "internal" dependency I add to plugin. The result is mess in local repository and a lot manual steps needed to rebuild project.
Is there any way to say Maven that it should build the plugin first (with deps), and later use it during my-project building?
I would suggest using profiles in your situation. You could consider two profiles in the root-project's pom.xml: build-plugin and build-project. Module aggregation (<modules> list) would be moved to these profiles. E.g. the build-plugin profile would contain:
<modules>
<module>my-library</module>
<!-- + any other "internal" dependencies needed to build the plugin -->
<module>my-maven-plugin</module>
</modules>
Similarly, the build-project profile would contain the module list needed to build my-project. Then,
mvn clean install -P build-plugin
mvn clean package -P build-project
would be your commands invoking the build of my-maven-plugin and my-project, respectively. Both these commands would be executed from root-project's directory. If you need to run them in sequence most of time, a simple shell script could do the work...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With