Disable Maven Settings inheritance - maven

Maven has concept of global settings and user-level settings, that compose into effective-settings for build purposes, see this.
The question is, how can I disable inheritance of global settings inheritance for some particular build?
Command mvn verify -s settings.xml overrides only user-level settings for me, global ones are still visible in effective-settings.

If you are working on an maven-invoker-plugin test you can define a separate settings.xml file in the src/it/....
If you need having a separate repositories or using particular dependencies you should use the mock repository manager which is intended for such things.
The basic test if you integration tests is correct start with empty local repository by using mvn clean version which should work.
As an example you can take a look at the versions-maven-plugin which uses such setup.

Related

Override maven scope configuration?

My project has a dependency for which the scope must be set to provided. But when I run the project from my local environment, the scope must be compile. Is there anyway I can define the scope as provided in my pom, but override it when I run from my local environment?
I think the best approach would be using maven profiles, in this way you can leave dependency with proper scope in main dependencies tag and re-declare it whithin your "local" profile.
Then you just have to invoke
mvn clean package -Plocal
to run the build triggering local profile and therefore getting the dependency with the modified scope.
In this way standard build is unaffected and you can run all your build locally with all needed changes as well

Can I override individual maven plugin settings in settings.xml (or elsewhere)?

My team uses a plugin that generates javadocs that adds about 20 - 30 seconds to our build time. I don't ever use these javadocs, so I would like to eliminate them from my build.
Changing the POMs is not possible for various reasons, so I can't add a profile to conditionally use those (even if they default to true!).
My read of the docs suggests that this is not possible in settings.xml since it's a truncated version of and doesn't contain .
How can I override plugin settings locally?
Skip it using a system property:
mvn -Dmaven.javadoc.skip=true clean install
You can change some behavior using system properties, e.g. the value of the configuration settings skipTests is bound to the user property skipTests, so when you invoke Maven with -DskipTests=true, it will implicitly set this value.
However, that works only if a) your POMs rely on properties to make configurations, b) your POMs do so far not set these configuration settings explicitly and c) it is not some special value that cannot be set via properties, e.g. config settings that accept multiple values such as some "includes/excludes" settings.
If the plugin has an option to skip its run and you are inheriting it form a parent pom, yes you can "re-define" the plugin config in the child poms.
Here are some related answers that could help you:
Disable a Maven plugin defined in a parent POM

How do I set up Spring and Maven environment for working offline?

I need to set up Spring and Maven for working offline. I am working with Spring Tool Suite.What environment variables do I need to configure besides M2 env var? When I try to add dependencies in pom.xml, and type springframework, nothing comes up in the search bar. I get "Core exception Could not calculate build plan Plugin org.apache.maven.plugins:m. I understand STS uses web services to locate the jars, so how do I configure Spring and Maven to work offline? Thank you.
Maven uses central repositoty to update dependencies via internet if you want run it offline you need to configure you local repository.See Setting local Maven repository
This is something that you will find very difficult or near impossible unless you somehow get all the relevant jars from spring and place them in your .m2 repo directory.
Your question has been asked a number of times on here ...
Have a look through these 2 questions which I assume is exactly what you have encountered.
Question 1
Question 2
Also one last note ...
After you setup your variables did you restart your PC I know sometimes I forget to do this when updating environment variables.
Before you go offline run the following:
mvn dependency:go-offline
That will download all your dependencies and plugins that you need to build your project into ~/.m2/repository.
Once you've run that you can now build your project offline using the '-o' flag:
mvn install -o
It's also possible to configure the offline mode globally by setting the offline property in the ~/.m2/settings.xml file:
true

How do I separate configuration for maven command line mojo invocation from global plugin configuration?

I'm using the cargo plugin to deploy my app to a remote server during the build. To do this, I have a configuration element for the cargo plugin. Since there are two executions that use this single configuration, I use a global configuration element, i.e. it's not inside the executions.
I also want to execute a CLI invocation of the cargo:run mojo on this pom. However, I don't want this execution to use the configuration at all.
How can I do this?
Check out maven profile. It's able to help you to deal with configuration divergence in different environments.

is it possible to do a Maven build using Build Forge?

Is it possible to do a Maven build using Build Forge? Currently we use Build Forge, ClearCase and ClearQuest with Ant scripts; would like to try a Maven build. Not sure if I can I have no test environment so don't want to mess up any thing and still learning all this stuff too
Maven can be invoked from any build automation framework.
Create a buildforge step that invokes your Maven build as follows:
mvn -s /path/to/maven/settings/files/mysettings.xml clean package
Explicitly selecting the settings file is recommended as this enables you customise the Maven configuration for each project.
Project isolation can be further enhanced by ensuring that each project has it's own local repository location (See the "localRepository" parameter in the settings file documentation)

Resources