multi-module project and ${basedir} placeholder - maven

I have a multi module project with the following structure:
-parent
-module1
-module2
-src
-main
-javadoc
-stylesheet.css
-pom.xml
I want to configure the javadoc plugin in the parent POM. But, I need to specify the path to the stylesheet.css file. So, I use the value ${basedir}\src\main\javadoc\stylesheet.css.
But, when I look at the effective POM for the child modules, the ${basedir} is replaced by the absolute path of the child module base directory, but there is no src/main/javadoc/stylesheet.css file there. Copying the stylesheet.css file in the child modules is not a solution, I think.
Thanks

${basedir} (short for ${project.basedir}) is a directory where project's pom.xml file resides. Therefore, for child modules this property is going to contain paths to module1 and module2 directories correspondingly.
If you want to configure javadoc plugin in the parent pom.xml so it would be effective for child modules, you should use ../src/main/javadoc/stylesheet.css.

The Maven Javadoc plugin allows you to include stylesheet resources that are stored in a JAR file, as described here: http://maven.apache.org/plugins/maven-javadoc-plugin/examples/stylesheet-configuration.html
This would allow you to create a resource-only JAR, add it to the dependencies list for your javadoc plugin, and load the resources from there. This would eliminate the need to either duplicate stylesheet files, or reference a shared set deployed in your parent POM.

Related

How to copy all the dependencies in Maven project modules to a directory?

I have a big local maven project that contains multiple modules which are inturn maven projects and are dependent on one another.
Ex.
parent pom.xml
<pom>
<module1> #jar
<module2> #dependent_on_module1.jar
<module3> #
</pom>
I have mentioned the sequence to build those modules in the parent pom.xml .
I also mentioned where to place the artifacts when they're built in groudId and artifactId.
But in the dependencies for all those modules, I have mentioned a common local system path for all those modules.
Is there any way to copy all the artifacts which are being created for modules when maven build is performed on the parent pom to a specific directory that can be dynamically mentioned when the maven command is run.
I have searched for maven copy command. But looks like it's not going to do what I want.
Any suggestions?

overwrite path to parent in maven module

For some investigations I have used another pom which calls module poms. Unfortunately from the documentation it looks like properties are only overwritten if that pom is configured for all modules as a parent
Is there a parameter to run a maven module pom with a command that overwrites the relative path to the parent pom ?
Or even better to set that path in a called pom to make it parent for all modules?
AFAIK, it is not possible.The reference of parent pom cannot be parametrized because the parent pom resolution happens before evaluation of the properties (because it is parent pom who can also define properties for your pom).
In order to change a set of properties in your pom, rather than specifying them in a pom you wanted to plug in as a adhoc parent pom, you can create a shell (or windows cmd) script and specify the properties as -D parameters of your maven command.That is
mvn clean install -Dthe.property.1.to.override=value1 -Dthe.property.2.to.override=value2 ...
You can also specify your properties and values in a property file and let maven load this file by using Maven Properties Plugin.

Maven multi-module project - copying all dependencies into a single tar.gz

I'm looking to pull all of the dependencies from each module of my maven project and stick them into a single tar.gz file using the maven-assembly-plugin.
I currently have a pom setup as a parent to all of the modules. My idea was to use the maven-dependency-plugin to copy all of the dependencies to a single folder in the parents directory however when i use
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
The dependencies are copied into the modules build directory. Is there any way to set this output directory to one inside the parent project?
You are going at it the wrong way.
Instead of creating this archive inside the parent POM, you should create another module which will be responsible for creating it. This new module will have dependencies on all the other modules.
To create the archive, you need to use the maven-assembly-plugin. I strongly suggest that you read Chapter 8. Maven Assemblies of the Maven book to get you started with using assemblies. Basically, an assembly is created with the help of an assembly descriptor. In your case, you will need to configure this descriptor to use the tar.gz format.

Maven: Get artifact list of sub modules

I have a root parent maven module which has lot of sub-modules that build jar files as artifacts.
I cannot change all sub-module pom.xml files.
From the root parent pom.xml is there a way I can get a list of all jars (artifacts) built by sub-modules?
Preferably after the package phase is complete?
PS: As a part of root module build I want to generate a report using a tool which requires this list of jar files.
There's a target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst in a Maven project.
You can use the GMavenPlus Plugin and Walking the File Tree to gather these files and put their content where you want.
Another option is to develop an own Maven plugin that does the same.

maven multi module project: is relativepath necessary?

I'm trying to link together a set of disjoint maven projects into a standard multi module project.
The interesting thing is that the modules are currently not arranged in a natural heirarchy. If I link together with a parent pom, then the reactor won't start up until I add relativePaths to the parent stanza in the child pom XML files.
If the GAV details are correct in the parent version vs the child, and the child modules are all linked in the parent pom - shouldn't this be enough?
in simple terms - for a non-standard directory structure, is the relativePath strictly necessary for a multi module maven project?
Thanks, Ace
in simple terms - for a non-standard directory structure, is the relativePath strictly necessary for a multi module maven project?
The answer is: Yes!
If the parent is not yet installed in the local repository and if the directory structure is for example:
.
|-- my-module
| `-- pom.xml
`-- parent
`-- pom.xml
The child modules cannot inherit the groupId / version of their parent POM without setting the <relativePath> element.
See http://maven.apache.org/guides/introduction/introduction-to-the-pom.html#Example_2

Resources