如何配置mvn依赖:在pom.xml中分析

Ast*_*rio 5 java xml configuration dependencies maven

我想mvn dependency:analyze从命令行使用来手动检查依赖关系问题。问题是我找不到在pom.xml. 必须在命令行中提供所有参数。

所以我必须总是使用

mvn dependency:analyze -DignoreNonCompile
Run Code Online (Sandbox Code Playgroud)

什么,我缺少的是设定的方式ignoreNonCompilepom.xml在插件配置。

像这样的东西:

<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>
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

如果我使用

<goal>analyze-only</goal>
Run Code Online (Sandbox Code Playgroud)

然后在构建期间运行插件,并使用配置。但我不想让它在构建中运行,只能手动请求。并且手动运行不会遵守该参数。

我可以在pom.xmlnamed 中设置一个属性ignoreNonCompile,但这将在构建中设置此参数并手动运行。

有没有办法只配置 的行为mvn dependency:analyze

Tun*_*aki 5

问题是你在一个<execution>块内设置你的配置。这意味着配置将只绑定到特定的执行;但是,在命令行上调用时mvn dependency:analyze,它不会调用该执行。相反,它将使用默认全局配置以默认执行方式调用插件。

ignoreNonCompile是该插件的有效配置元素。你必须使用

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <configuration>
        <ignoreNonCompile>true</ignoreNonCompile>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果您不想为上述所有执行定义全局配置,则可以保留特定于执行的配置,但您需要告诉 Maven 使用以下命令显式运行该执行

mvn dependency:analyze@analyze
Run Code Online (Sandbox Code Playgroud)

analyze执行 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>
Run Code Online (Sandbox Code Playgroud)

  • 我相信您也可以使用“default-cli”(代表默认命令行界面)作为执行 ID。然后,如果您运行“mvn dependency:analyze”,Maven 将默认从该执行中获取配置。如果您知道从命令行运行时始终需要相同的配置,这可能是一个不错的选择。 (2认同)