Where does maven take the default version of findbugs? - maven

I'm trying to make Maven use a specific version of findbugs when running
mvn findbugs:findbugs
It seems to ignore whatever version I set inside the POM. I tried running it using just a test POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
</project>
-which just seems to use findbugs version 2.5.2 by default. Where did this version come from?

It is the latest version of the plugin. see Maven central repository
findbugs:findbugs refer to org.codehaus.mojo.findbugs:findbugs
Other refs:
MOJO Production Plugins
FindBugs Maven Plugin' project page

Related

Download Maven artifact with version range

I need download specific Maven artifact using version range e.g.:
GroupId:org.apache.logging.log4j
ArtifactId=log4j-api
Version=[2.17.1,)
Right now I need it in one CI job.
How can I do it?
I was hoping to find an easier solution, but at least this works:
Create pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.vondr</groupId>
<artifactId>maven-dependency-download</artifactId>
<version>1.0.0</version>
<properties>
<dep.group>org.apache.commons</dep.group>
<dep.artifact>commons-lang3</dep.artifact>
<dep.version>3.12.0</dep.version>
<dep.type>jar</dep.type>
<dep.classifier></dep.classifier>
</properties>
<dependencies>
<dependency>
<groupId>${dep.group}</groupId>
<artifactId>${dep.artifact}</artifactId>
<version>${dep.version}</version>
<type>${dep.type}</type>
<classifier>${dep.classifier}</classifier>
</dependency>
</dependencies>
</project>
And then use it to download artifact using command:
mvn dependency:copy-dependencies "-DoutputDirectory=./downloaded-dependencies" -Ddep.group="org.apache.logging.log4j" -Ddep.artifact="log4j-api" -Ddep.version="[2.17.1,)"
Additional information
Basic description is here:
http://vondrnotes.blogspot.com/2022/09/download-maven-artifact-with-version.html
Working example is here:
https://github.com/bugs84/download-maven-dependency-with-version-range

How to configure/override Maven property used as parent version in dependencies?

Suppose there are two 3rd-party Maven artifacts with the following POM.XMLs:
artifact1 POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group1</groupId>
<artifactId>artifact1</artifactId>
<version>${artifact1.version}</version>
<packaging>pom</packaging>
<properties>
<artifact1.version>0.0.1-SNAPSHOT</artifact1.version>
</properties>
<modules>
<module>../artifact2</module>
</modules>
artifact2 POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>artifact2</artifactId>
<parent>
<groupId>group1</groupId>
<artifactId>artifact1</artifactId>
<version>${artifact1.version}</version>
<relativePath>../artifact1</relativePath>
</parent>
They are built normally using
mvn clean install
Now, if I try to reuse artifact2 in a 3rd POM.XML:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group2</groupId>
<artifactId>artifact3</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>group1</groupId>
<artifactId>artifact2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
After executing...
mvn clean install
...the build fails trying to locate group1:artifact1:pom:${artifact1.version}
[ERROR] Failed to execute goal on project artifact3: Could not resolve dependencies for project group2:artifact3:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at group1:artifact2:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for group1:artifact2:jar:0.0.1-SNAPSHOT: Could not find artifact group1:artifact1:pom:${artifact1.version} in central (https://repo.maven.apache.org/maven2) -> [Help 1]
And setting the property in the command-line doesn't work either:
mvn clean install -Dartifact1.version=0.0.1-SNAPSHOT
How can I use artifact2 as a dependency?
<parent> doesn't allow variables. Because in order to get a list of variables Maven first has to build Effective POM and for this it needs to resolve parents.
Even if there is some version of Maven that allowed such module to be installed it's not a working solution in general. Maven's ideology is that all the dependencies (including parent) could be downloaded from a repo and are not necessarily present on local FS/in the reactor. With properties in the parent dependency definition you violate this rule.

Install artifacts from artifactory to local repository

I have an artifactory which stores artifacts, this is a given pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.test2.test3</groupId>
<artifactId>web-gen</artifactId>
<version>v2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test dynamic web layer</name>
</project>
How can I install the given artifact to my local repository?
mvn install, mvn install:file and others can't help. Pretty frustrated about it...
The simplest solution would be to use it as a dependency which will automatically download the artifact and put it into your local repository.
Otherwise you can use the maven-dependency-plugin by using the get goal:
mvn dependency:get -DartifactId=WhatEver -DgroupId=XX -Dversion=xxx -Dclassfier=..

Netbeans Maven annotations not supported in source 1.3, use source 5

When building my projects using Maven from Netbeans 6.7, I get these error messages:
Error annotations are not supported in -source 1.3 (use -source 5 or higher to enable annotations)
I've already seen on this thread that I need to add a maven-compiler-plugin configuration to my POM.xml, but I don't want to do this to every project. Can I set this in one central location that will affect all my maven projects? In settings.xml somehow?
I've already configured Netbeans to use Maven 3.0.3 and my JAVA_HOME is pointing to JDK 1.5.
Even if it is quiet simple using Netbeans to configure this in each project :
right click on your project,
select «properties»,
select «sources» in the project properties window,
choose the «source/binary/format» to 1.3
click OK will update your pom correctly.
A better approach will be to use (inheritance in poms) .
Configure the plugin in a parent pom.xml :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent-pom</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.3</source>
<target>1.3</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then after, your modules can inherit this behaviour this way :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.mycompany</groupId>
<artifactId>parent-pom</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>mavenproject1</artifactId>
<packaging>jar</packaging>
<name>mavenproject1</name>

Release maven project removing automatically SNAPSHOT dependencies

I want to make my first release of a multi-module maven project using the maven release plugin. I´m facing a problem in the release:prepare step because I have SNAPSHOT dependencies.
<project ...>
<parent>
<artifactId>project</artifactId>
<groupId>ccc.aaa.bbb</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>common</artifactId>
<packaging>pom</packaging>
<name>common</name>
<modules>
<module>daoModule</module>
<module>configModule</module>
<module>exceptionModule</module>
</modules>
<scm>
...
</scm>
<distributionManagement>
<repository>...</repository>
<snapshotRepository>...</snapshotRepository>
</distributionManagement>
</project>
And the modules extend this as its parent:
<project ...>
<parent>
<artifactId>common</artifactId>
<groupId>ccc.aaa.bbb</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>exceptionModule</artifactId>
<name>exceptionModule</name>
<build>
...
The plugin changes the the version of the artifact 0.0.1-SNAPSHOT to a release version 0.0.1 , and creates the new snapshot version id 0.0.2-SNAPSHOT.
¿Is there any way to change automatically the version of the parents from 0.0.1-SNAPSHOT to 0.0.1 - the release that is going to be created-?
Thanks.
It should work when doing release:prepare from the aggregator project level that contains all the modules you're interested in. So your common, project artifacts and all the modules should be released at once. Also look at autoVersionSubmodules switch to do a little less typing.

Resources