Why doesn't Maven automatically create a settings.xml file? - maven

I'm writing an tech article about Maven vs Jenkins, but one thing that came up in my research is the fact Maven doesn't automatically create a settings.xml file. It has to be manually created by the user themselves if they want to change global parameters. Why is that? Does Maven exclusively use values in pom.xml for projects?
So far, I've done my research on how users have to create a settings.xml file. But unfortunately, most of my sources don't explain why this is the case. Most just say, "settings.xml isn't automatically created, the user must create it," and that's it.

I mean, Maven runs with default parameters if you don't have one, and so it is not mandatory to have one.

Related

maven archetype generation with custom root folder name

I am using mvn archetype:generate and I am supplying as input parameters the artifactId as well as the repositoryName that I want to use for git. I would like that the root folder name of the project generated is the repositoryName and not the artifactId, which is the default behavior.
According to the documentation, you can create a post generation groovy script that does different actions and moving the project to a new folder is also possible, as mentioned here. This solution worked out for me. However, right after the output of my script, there is the default log line that says
[INFO] Project created from Archetype in dir: <old_dir>
This is very confusing and I'm wondering if there is a way to change that. Maybe changing the request.outputDirectory would provide a better solution, but I didn't manage to get that to work and I am also wondering what is a good structural solution.

Maven Archetype creation via Eclipse

I am willing to create an archetype which will be useful to create a lot of projects sharing the same architecture. I followed the maven guide and read some bloggers guides but even with these informations I am struggling.
I have some constraints for my projects :
All the project code is in a package which must be something like com.ei.app.project (app and project are vars I would like to set during the project generation)
I have dependencies I would like to be present in my POM when the project is generated
I have some scripts file with data (paths, app name...) and I would like to set them according to the project parameters, and if it is possible add additional parameters.
We don't use the official maven repo but set up another online repo. We have a strict security policy an whenever we have to add a lib into the repo it takes a lot of time for verifications.
How can I achieve this ? I tried several solutions but encountered a lot of errors. If you have a complete step-by-step guide in english or french that would be fantastic, but I would also like to understand how it works.
Many thanks for your help
Let me answer parts of your question.
From an example project, you can create an archetype by using archetype:create-from-project (https://maven.apache.org/archetype/maven-archetype-plugin/create-from-project-mojo.html).
You can supply a property file that will be used to replace actual values (like 1.0.0-SNAPSHOT) with references (like $version). All filtered files will be treated as velocity templates so that you can use $-type replacement.
Your repository restriction may be problem because you probably need dozens of artifacts to make the archetype plugin run.
I finally created a "base" project with all I need inside (libraries, main Vert.x class...), and developed a script to replace a template value (i.e __projectName__ ) in dir / file names and inside configuration / pom.
It's close enough to what we need and provide a cool replacement tool for my company, which will be used for multiple purposes.

How to skip a maven build step without modifying the pom itself?

We have a maven based Java EE project controlled by the customer. For internal reasons, we cannot execute one of the build steps, but the rest works fine and produces the jar we want.
Since editing the pom file would require taking care when committing to customer's SVN and copying the pom file would require taking care to sync changes comming from there, we are looking for a way to skip this specific step in the build section during the maven call itself, so to say mvn clean install but-leave-out-this-build-plugin-step, is there any?
Edit:
The plugin in question is the rpm-maven-plugin, which prevents the build from running on Windows. We found information how to make it work which won't really fit in our current setup. And since we cannot modify the customer's pom, I was looking for a way to trigger the skipping externally. But maybe there are other ways to just ignore/skip/fake this step?
It depends on what plugin you want to skip. Many plugins have ability to be skipped via system property (-Dblabla).
For deploy plugin it is -Dmaven.deploy.skip=true, for surefire -DskipTests=true.
Read plugin documentation, maybe you can find skip property
The rpm plugin hase a property disabled, unfortunately it is not accessible by a property. So, if setting this property in the customer's pom (or asking for editing it) with a default value of false is an option, this may be the solution.

Maven how to handle multiple projects and settings.xml in same PC

I want to have multiple (local) settings.xml files in my PC for my Maven projects, one per project. What is the best way of handling these settings.xml (hopefully somehow through version control)?
I know that each developer (and the CI server) will want to have some different variables in those settings.xml.
I am thinking something like one settings.xml in subversion per project, to provide a skeleton with some empty fields so that everyone can copy and paste the settings.xml file to their local directory where it gets picked up by Maven and also fill in the blank values that are unique per environment/user. Bear in mind, I am not referring to stuff that can be set via profiles, it's more like usernames and passwords and such.
This leaves us with the problem of multiple settings.xml files. IntelliJ as I see has Maven configuration per project so I shouldn't have any trouble setting separate locations for every project. As for the command line, do I really need to type in the path to my settings.xml file every time I run something (via the -s command)?

Maven: Is it possible to have more than one settings.xml files?

I have a multimodule project. All of the modules, but one are different. There are some things in the settings.xml file that I want to be different in the one module than from the rest.
Is it possible to have two settings.xml file and use them for different modules?
Think of the settings.xml as the configuration for your installation of maven. It determines the behavior of maven across it's use in your various projects.
This being said, if an individual project, i.e. a pom, requires something unique, it should be in that pom.
I think the thing to remember is that the project should be able to build on an individual dev's machine without any special intervention. In other words, the ideal case is that a given pom can successufl execute mvn install in a vanilla environment. So, don't put something in it that requires tweaking for a dev to get it to work. Also don't put anything in your settings.xml that enables a project to build, but then puts the burden on other devs to know what secrets are in your settings.xml.
You can set up different things in your individual pom files. What's in the pom files will override what's in settings. For instance, if your child poms sets up different repositories they'll be used over what is defined in settings.xml. Settings.xml is the default is nothing else applies. Depending on exactly what you want to do you might also take a look at the profiles feature.

Resources