I'm a little confused by the Maven documentation - should lifecycles be defined in lifecycles.xml or lifecycle.xml? Even the Sonatype reference talks about these two names seemingly interchangeably!
Still confused about components.xml too - if there's any good reference for that can you post it please?
Thanks,
-Dave
It should be lifecycle.xml (see Lifecycle Mappings):
Configuration of custom lifecycle mappings for the plugin, as generally stored in META-INF/maven/lifecycle.xml in a plugin's jar artifact.
lifecycles.xml, with an 's', appears only once in the Maven source, commented out as a distinct and never-used file.
Also, components.xml, as in Overriding the Default Lifecycle:
In your plugin project, create a META-INF/plexus/components.xml under src/main/resources.
See Creating a new phase for a full example.
Related
When configuring the Surefire Maven plugin for Quarkus, I have come accross the following in the doc
<maven.settings>${session.request.userSettingsFile.path}</maven.settings>
For my project I would also need to do the same thing for the settings-security.xml file because we use password encryption.
In Quarkus this can be done using
<settings.security>
I can define this with a project property in the pom.xml with the hard-coded path of the settings-security.xml file in my CI/CD environment (it is not the default one). But ideally I would like to extract it from the Maven execution environment using something similar to ${session.request.userSettingsFile.path}
I have 2 questions (I still have a very limited experience of Maven for the moment, so please bear with me)
I have found plenty of examples with the ${session.request.userSettingsFile.path} property, but no documentation. Anyone know where these properties are documented? It is not at all clear to me where they come from.
Is there an equivalent to ${session.request.userSettingsFile.path} for the settings-security.xml file, or do I have to define the path in the project properties?
Thanks
I am working on a plugin. This plugin gets attached to a project that does not apply the java plugin nor the java-library plugin but which should functionally "look" like a Java project[1]. Which means that it should publish a POM including dependencies. The exact dependencies are known and have been collected in a Configuration.
However, I cannot figure out how to manually attach dependencies to the MavenPublication such that they make it into the published pom (aside from directly editing the pom xml).
MavenPublication shadowMavenPublication = publishingExtension.getPublications().create( "mavenShadowArtifacts", MavenPublication.class );
// `shadowPublishArtifact` is a class defined in the plugin
shadowMavenPublication.artifact(
shadowPublishArtifact.getFile(),
(mavenArtifact) -> {
mavenArtifact.setClassifier( shadowPublishArtifact.getClassifier() );
mavenArtifact.setExtension( shadowPublishArtifact.getExtension() );
}
);
So at this point I have the MavenPublication and added my custom artifact to it. Internally this MavenPublication contains a number of "dependencies" as instances of MavenDependency. E.g. DefaultMavenPublication#runtimeDependencies, DefaultMavenPublication#apiDependencies, ... But those are things defined on internal-only contracts.
Using just public APIs, how can I add dependencies to get added to the pom?
P.S. As a bonus, answer the question on the Gradle forums and get points there too! :D
P.S.S. These dependencies come from another project (hibernate-core) in a multi-project build. The user has configured those dependencies themselves. I just "consume" those dependencies with a series of "dependency substitutions". That "source project" defines some exclusions to its dependencies. How can I access those exclusions do be able to transfer them to the dependencies I am creating for this copy project (hibernate-core-jakarta)?
Thanks!
[1] Its a long back-story, but the gist is that this plugin integrates the JakartaTransformer. The project is completely generated using the transformer. The tasks added by those 2 plugins cause problems.
MavenPublication class has pom property - You need to construct (or provide in Your plugin some API for that purpose) pom with all necessary dependencies. It will be published alongside with artifact.
As far as I know, dependencies are attached to the POM by evaluating the configurations of a software component: MavenPublication.from(SoftwareComponent) (source: DefaultMavenPublication).
The idea would be to provide a customized software component. This is only possible through a custom plugin, according to Creating and publishing custom components.
Does anybody know how to find all maven system properties?
If I do mvn --help, I can see
-D,--define <arg> Define a system property
But no way to find an exhaustive list of those properties on internet.
Thank you for your help.
It would be great to have such a list, but the available / recognized properties are in the hands of plugin authors and there is no global registry. They may even change between plugin versions. However, they usually are part of the plugin documentation.
Some commonly used Maven properties:
maven.compiler.source
maven.compiler.target
maven.compiler.testSource
maven.compiler.testTarget
project.build.sourceEncoding
project.reporting.outputEncoding
maven.javadoc.skip
maven.test.skip
Furthermore, you can define your own property and use it anywhere in your pom.xml file via ${my.custom.property}.
Links:
https://maven.apache.org/pom.html#properties
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
https://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html
I use different maven plugins to resolve properties from a file (properties-maven-plugin) and manipulate them during the life-cycle (gmaven-plugin).
In the end (at deploy) I would like to have all those properties visible in the output pom, but so far I haven't found out how to do that.
Does the maven-help-plugin would help you ?
mvn help:effective-pom
http://maven.apache.org/plugins/maven-help-plugin/usage.html
You would see the effective pom but without any comments, so you won't be able to persist it.
As far as I know, what you require does not exist.
I have the following property in Maven and I cannot find any information about it:
<properties>
<!-- development mode (exclude in production) -->
<exclude.bootstrap>true</exclude.bootstrap>
</propertes/>
Thanks for pointing me to the right documentation.
I haven't seen something like this before. IMHO this is just a regular, your own (or POM's author) property, probably used somewhere in this POM or its modules. There is an option that this is a special property, maybe related to some of declared plugins, but - as I said - I haven't used a plugin that uses this.