Home > Enterprise >  Configure maven plugin version without changing pom.xml manually
Configure maven plugin version without changing pom.xml manually

Time:04-09

Problem Description

I'm working with a collection of old projects from defects4j. My problem now is that since I want to combine those projects with a newer maven plugin, a regression test tool, there are some issue with the maven surefire plugin version.

In the pom.xml that come along with the projects, there are no specifications of surefire version:

  <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <executions>
          <execution>
            <id>plain</id>
            <configuration>
              <includes>
                <include>**/*Test.java</include>
              </includes>
              <runOrder>random</runOrder>
            </configuration>
          </execution>

        </executions>
      </plugin>

However, the regression tool (made into a maven plugin), require surefire version of 2.14 and above. So I get error like this:

[ERROR] Failed to execute goal edu.illinois:starts-maven-plugin:1.4-SNAPSHOT:select (default-cli) on project commons-lang: Unsupported Surefire version: 2.12.4. Use version 2.13 and above

Efforts Done

I checked several stackoverflow posts, and they talked about the effective pom. When I run mvn help:effective-pom, I can see that the version of surefire used is

  <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12.4</version>

Question

Since the project collection in defects4j does not specify surefire version in their pom.xml, is there a way to specify the surefire version used to 2.14 or above from command line? I want to prevent from manually editing the pom every time.

Update

by running mvn dependency:resolve-plugins, i get

Plugin Resolved: maven-surefire-plugin-2.12.4.jar

So it seems to me that somehow maven use 2.12.4 as a default. The reason maybe that I used this version previously. How do I fix this? Without modifying the pom manually?

Any advice will be welcomed!

Update:

Problem solved by editing maven's super pom.

CodePudding user response:

  1. Maven takes the newest version from the repository if there was no version fixed in your POM, parent POM or the super POM (from which every Maven project inherits).

  2. It is best practise to fix a version "manually" in the POM. The best place for this is a parent POM from which the projects inherit (this means, only one place to change).

  3. You cannot just supply a version from command line. Unless you do some tricks like putting <version>${surefire.version}</version> into the plugin definition and set this property from command line.

CodePudding user response:

I'm 4 years removed from working with poms so don't remember everything, but consider a couple of things.

First, since the pom you show isn't specifying the version of surefire to use I don't think that the 2.12.4 version can be coming from that directly. Try getting a dependency tree to see where things are coming from. Try How can you display the Maven dependency tree for the *plugins* in your project? for that and a few other suggestions.

Second, I think I recall that in your own pom you should be able to specify the version of plugin to associate with a dependency that doesn't specify one. You'll have to research that option yourself.

I think your best bet is the dependency tree to find what's using what and where things are coming from. If you get the tree and still can't figure out what to do try adding the tree output to your question. (You can edit out parts that are proprietary, or clearly unrelated.)

  • Related