Maven plugin executing another plugin - maven-2

I'm trying to create a new plugin to package my latest project. I'm trying to have this plugin depend on the maven-dependency-plugin to copy all my projects dependencies.
I've added this dependency to my plugin's pom, but I can't get it to execute.
I have this annotation in my plugins main Mojo:
#execute goal="org.apache.maven.plugins:maven-dependency-plugin:copy"
I've tried a few other names for the goal, like dependency:copy and just copy but they all end with a message saying that the required goal was not found in my plugin. What am I doing wrong?
Secondary to this is where to I provide configuration info for the dependency plugin?

Use the Maven Mojo executor by Don Brown of Atlassian fame to run any other arbitrary plugin.
The Mojo Executor provides a way to to
execute other Mojos (plugins) within a
Maven 2 plugin, allowing you to easily
create Maven 2 plugins that are
composed of other plugins.

Have you tried to create your own packaging type? Then you can define your own lifecycle mapping, i.e. bind goals to phases. In this case you can bind the dependency:copy-dependencies goal to your packaging phase and you don't have to wrap the goal into your own Mojo.
See also: How do I create a new packaging type for Maven?

Related

How to automatically generate JAXB classes on build in IDEA?

I have an IDEA project that uses auto-generated JAXB classes from .xsd files. I have “client” and “server” modules that include a “common” module that contains, among other things, the JAXB classes.
I do not want to keep generated code under source control, but if the generated java classes do not exist, “client” and “server” modules do not compile. How to make IntelliJ automatically run JAXB before building?
There is no direct way to do it only with IntelliJ IDEA, you will need to use Ant or Maven or some other external process that will perform the code generation.
Check out jaxb2-maven-plugin.
In IntelliJ IDEA you can execute Maven or Ant before compilation.
In the build system's tool window you can bind a phase or a plugin goal to IDEA's build process.
For example the jaxb2-maven-plugin can be executed Before Rebuild or Before Build with a secondary click on the goal:
Another option would be to bind the goal to a lifecycle phase and execute the phase like 'generate-sources' before rebuild. In case of the jaxb2-maven-plugin the goal xjc is by default bound to the generate-sources phase of Maven.

Building Products with Maven

I'm fairly new to Maven and I'd like to use it to build a multi-module project.
Lets assume I have the following svn repository structure:
- /trunk/common-services/login-service
(.jar) [re-usable components]
- /trunk/services/mybusiness-service
(.jar)
- /trunk/webservices/mybusiness-rest
(.war)
- /trunk/products/myproduct
(pom) [issue mvn command here]
What I'd like to be able to do is to checkout and build the entire "product" from a single pom using a single mvn command (from a developers pov as well as a CI pov). It's safe to assume that I have the trunk checked out.
How do I do this using Maven? I've looked at the Maven reactor plugin, but I can't figure out how to use it correctly (if it is the correct plugin to use).
The reactor plugin assumes each module has its pom.xml.
For your use case, you would want to create a pom.xml for each module (login-service, mybusiness-service and mybusiness-rest). You would specify the dependencies in each of the modules. For instance, if your mybusiness-rest depends on login-service and mybusiness-service, you would specify these projects as dependencies.
You would have a pom.xml in /trunk which specifies each of the modules to be built. You can use the reactor features in this pom.xml to determine, when to build (or not build) specific modules.
Your developers and CI can build using this single pom.

How to convert Ant project to Maven project

How to convert a Ant project to Maven project? A sample project that would link (a Wicket project)
Thanks
The nice part of using maven is that most standard stuff works automatically once you do things the maven way. For a simple webapp:
Create a pom with groupId, artifactId and version (packaging: war)
Add the required dependencies to the pom
move the
java sources to src/main/java,
resources to src/main/resources,
webapp content to src/main/webapp,
test content to src/test/java and src/test/resources
set the compiler compliance version using the maven compiler plugin
That should get you up 'n' running.
http://www.sonatype.com/people/2009/04/how-to-convert-from-ant-to-maven-in-5-minutes/
I don't know what your ant script looks like, but assuming its a basic script for building, you will need to create a pom.xml file for your project, add your dependencies, and then build it via maven.
For anyone who lands here in future, there is an easier way to find dependencies for maven using the file hashes. So, you won't have to guess artifact versions.
As per the below article, the idea is to generate a SHA1 checksum of the dependency that you want to find the information, then do a reverse search in Nexus repository manager using that hash. For the checksum generation, you can use Microsoft's FCIV (free) utility.
https://devreads.xyz/ant-to-maven-conversion-the-painless-method/

Maven 2, Liquibase and dbDoc

I'd like to generate liquibase's dbdoc as part of my maven site build, but I cannot figure out how to do this. My thoughts were to add maven-antrun-plugin to the reporting section of the pom, but I cannot have an node under plugin in the reporting section. Any ideas?
This is not supported by the Maven LiquiBase Plugin so either create your own report plugin or use the dbDoc Ant Task and the Maven AntRun Plugin to generate the documentation under target/site/.
In the later case, bind the plugin on one of the phases of the Site Lifecycle (this will require some testing but I think that pre-site, site or post-site would be ok) and add an entry in the left menu in the site descriptor.
You can create your own reports plugin, more information here:
http://docs.codehaus.org/display/MAVENUSER/Write+your+own+report+plugin

ant/maven integration

I have a project that is built and managed by Maven. I have a second project that has an ant build. I'd like to reference the maven project from the ant project and pull in all of the required dependencies. Can anyone suggest a way to do this?
thanks,
Jeff
The maven-ant-tasks work quite well for this sort of thing.
You can use Ivy:
Ivy can therefore be used to bring the
dependency management feature of maven
to Ant build files, for those of you
who already use Ant and who do not
want to setup a maven project.
Apache Ivy is an Ant library that can handle Maven-style repositories.
Here's a page which describes the differences between them and how to integrate the two.
There are a set of ant tasks for Mercury that allow you to perform dependency management tasks, specify configuration (e.g. server credentials), modify/alter the ant path and write to the repository. See this blog for details.
There are also Maven tasks for ant, though they are not as fully featured. Maven is moving towards Mercury (particularly for Maven3) so it makes sense to use the Mercury tasks.
The following configuration reads the dependencies from the specified pom and populates the specified variable with the resultant path:
<path id="my.compile.path">
<deps>
<dependency name="groupId:artifactId:1.0::pom"
pom="${basedir}/artifactId-1.0.pom"/>
</deps>
</path>
You can also use the Mercury tasks to deploy to a Maven repository using an Ant build file:
<repo id="myRepository"
url="http://localhost:8081/nexus/content/groups/public">
<auth name="myUser" pass="myPassword"/>
</repo>
<write repoid="myRepository"
name="my.group.id:my-artifact-id:1.0"
file="${basedir}/target/my-artifact-id.jar"/>