overwrite path to parent in maven module - maven

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.

Related

How to export custom parent pom properties to a file, from a child pom?

I have a parent pom with some custom properties and I would like to export those properties from one of the child to a file.
I tried maven-antrun-plugin with echo, but this works only with the child properties. I also tried to define child properties and assign the parent properties (e.g. <child.prop>${parent.prop}</child.prop>) but I got the same result.
Update:
It worked after I run mvn clean install on the parent.
The parent custom properties are available in child pom only after mvn install on the parent.

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?

Maven: how do I pass the artifactItems configuration to the dependency copy plugin from the command line?

I'd like the execute the Dependency Copy Plugin from the command line without the need to change the pom.xml file. I need to pass all configuration options from the command line. I can find some references to do it:
mvn -DuseRepositoryLayout=true dependency:copy
The problem is that I don't know how to set the <artifactItems><artifactItem> properties from the command line.
How would I invoke maven dependency copy plugin passing all necessary parameters in the command line?
You seem to mix two distinct goals :
copy-dependencies (referenced in your example) :
Goal that copies a list of artifacts from the repository to defined
locations.
copy (referenced in your link)
Goal that copies the project dependencies from the repository to a
defined location.
A user property in a mojo such as copy-dependencies provides a way to set a property from the command line with the -DMyUserProperty syntax.
From the copy plugin documentation you refer, you can read that the artifact property has as user property artifact.
So the example passing it from the command line is valid :
mvn dependency:copy -Dartifact=mygroupId:myartifactId:myversion
But the same plugin documentation doesn't specify any user property defined for the artifactItems property.
Besides, it is clearly stated :
Use artifactItems within the POM configuration.
So you are stuck to set artifactItems from a POM file.
As you don't want to bother with a POM and that you prefer to specify externally the dependencies to copy, dependency:copy-dependencies that provides a service enough close to which of copy-dependencies should better fit to your need as contrary to copy-dependencies, it provides a user property to include/exclude artifactIds/groupIds:
User Property: includeArtifactIds
...
User Property: includeGroupIds
You could so write something like :
mvn dependency:copy-dependencies -DincludeArtifactIds="myArtifactOne,
myArtifactTwo,..." -DincludeGroupIds="myGroupIdOne, myGroupIdTwo"

Overriding profile dependencies from parent pom

I am using maven 3.1 and my project inherits from a third party parent pom. The parent pom has a profile which must not be activated as it introduces conflicting dependencies.
In order to prevent the parent's profile from kicking in, I tried defining an "empty" profile with the same id in the child pom - hoping it will override the one from the parent, but that did not work for me.
Is it possible and if so how can you override dependencies introduced by a profile in the parent pom ?
You may explicitly deactivate the profile on the command line by putting a '!' in front of the profile ID, e.g.
mvn -P !profileIdFromParent install
More on profile activation in the Maven docs.

multi-module project and ${basedir} placeholder

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.

Resources