5

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?

flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Asturio
  • 535
  • 7
  • 23

1 Answers1

5

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>
Community
  • 1
  • 1
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Ok, I didn't new that with executions, thanks. Can I name the id anything? – Asturio Apr 19 '16 at 13:58
  • @Asturio Yes, the id can be anything you want. (well probably restricted alphabet letters :D) – Tunaki Apr 19 '16 at 13:59
  • 2
    I believe you may also use 'default-cli' (stands for Default Command Line Interface) as the execution ID. Then if you run `mvn dependency:analyze` Maven will pick up the configuration from that execution by default. This might be a good option if you know that you'll always want the same config when running from the command line. – user944849 Apr 19 '16 at 14:52