java - 如何配置maven依赖:analyze in the pom. xml

标签 java xml maven configuration dependencies

我想在命令行中使用 mvn dependency:analyze 手动检查依赖项问题。问题是我找不到在 pom.xml 中配置行为的方法。必须在命令行中提供所有参数。

所以我必须一直使用

mvn dependency:analyze -DignoreNonCompile

我缺少的是一种在插件配置的 pom.xml 中设置 ignoreNonCompile 的方法。

像这样:

<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>

但这行不通。

如果我用

<goal>analyze-only</goal>

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

我可以在 pom.xml 中设置一个名为 ignoreNonCompile 的属性,但这将在构建和手动运行时设置此参数。

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

最佳答案

问题是您在 <execution> 中设置配置堵塞。这意味着配置将仅绑定(bind)到该特定执行;但是,在命令行上调用时 mvn dependency:analyze ,它不会调用该执行。相反,它将使用默认全局配置以默认执行调用插件。

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

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

如果你不想像上面那样为所有的执行定义一个全局配置,你可以保留你的执行特定的配置,但是你需要告诉Maven to explicitely run that execution与:

mvn dependency:analyze@analyze

哪里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>

关于java - 如何配置maven依赖:analyze in the pom. xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36717516/

相关文章:

java - JAXB 更改默认命名转换器

java - 如何在Java eclipse中集成Maven 1.0

java - 支持桌面和桌面浏览器,但浏览器仍然挂起

java - java中的异步处理

java - 不显示 Android 应用程序的准确输出

xml - 如何在odoo的电子邮件模板中添加来自其他模型的字段?

java - 耳朵展开两次。 Maven、Jboss AS 7

java - maven javadoc :fix fails to autofix docs

java - 如何解决卡在 Android Studio 中的 "Waiting until last debugger command completes"?

java - 迭代Map的ArrayList的ArrayList