Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure mvn dependency:analyze in the pom.xml

I'd like to use mvn dependency:analyze from the command line to check manually for dependencies problems. The problem is that I couldn't find a way to configure the behavior in the pom.xml. All parameters must be supplied in the command line.

So I must always use

mvn dependency:analyze -DignoreNonCompile

What I'm missing is a way to set the ignoreNonCompile in the pom.xml in the plugin configuration.

Something like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>analyze</id>
            <goals>
                <goal>analyze</goal>
            </goals>
            <configuration>
                <ignoreNonCompile>true</ignoreNonCompile>
            </configuration>
        </execution>
    </executions>
</plugin>

But this don't work.

If I use

<goal>analyze-only</goal>

then the plugin is run during the build, and the configuration is used. But I don't want to have it run in the build, only manually requested. And running manually won't honor the parameter.

I could set a property in the pom.xml named ignoreNonCompile, but this will set this parameter in the build and running manually.

Is there a way to configure only the behavior of mvn dependency:analyze?

like image 998
Asturio Avatar asked Apr 19 '16 11:04

Asturio


1 Answers

The problem is that you're setting your configuration inside an <execution> block. This means that the configuration will only be bound to that specific execution; however, when invoking on the command line mvn dependency:analyze, it won't invoke that execution. Instead, it will invoke the plugin with a default execution using the default global configuration.

ignoreNonCompile is a valid configuration element for that plugin. You must use

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <configuration>
        <ignoreNonCompile>true</ignoreNonCompile>
    </configuration>
</plugin>

If you don't want to define a global configuration for all executions like the above, you can keep your execution-specific configuration, but you need to tell Maven to explicitely run that execution with:

mvn dependency:analyze@analyze

where analyze is the execution id:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>analyze</id>  <!-- execution id used in Maven command -->
            <goals>
                <goal>analyze</goal>
            </goals>
            <configuration>
                <ignoreNonCompile>true</ignoreNonCompile>
            </configuration>
        </execution>
    </executions>
</plugin>
like image 122
Tunaki Avatar answered Sep 28 '22 06:09

Tunaki