简体   繁体   English

在构建中使用maven传递依赖

[英]Use maven transitive dependency in build

Is there a way to use the transitive dependency of some maven module instead using the default maven lib version? 有没有办法使用某些maven模块的传递依赖,而不是使用默认的maven lib版本? For example: 例如:

My project has a dependency on qulice-maven-plugin, which depends on qulice-checkstyle, which depends on checkstyle libs. 我的项目依赖于qulice-maven-plugin,这取决于qulice-checkstyle,它依赖于checkstyle libs。 I want to to run checkstyle in my project, but using the same version and configuration which is loaded from these transitive dependencies. 我想在我的项目中运行checkstyle,但使用从这些传递依赖项加载的相同版本和配置。

If I run mvn checkstyle:checkstyle , which is the command for running checkstyle, it loads a default checkstyle version and uses its default configuration. 如果我运行mvn checkstyle:checkstyle ,这是运行checkstyle的命令,它会加载默认的checkstyle版本并使用其默认配置。 I don't want to copy all my configurations from these dependencies, I just want to maven to be smart enough to execute checkstyle using the dependencies defined above. 我不想从这些依赖项复制我的所有配置,我只是想要足够聪明,使用上面定义的依赖项来执行checkstyle。

Is there a way of doing this? 有办法做到这一点吗?

If I run mvn checkstyle:checkstyle it loads a default checkstyle version 如果我运行mvn checkstyle:checkstyle它会加载一个默认的checkstyle版本

If yours is loading version 6.18 then see https://stackoverflow.com/a/27359107/1016482 on how to override it to use a newer version. 如果您的版本正在加载版本6.18,请参阅https://stackoverflow.com/a/27359107/1016482 ,了解如何覆盖它以使用更新版本。

run mvn checkstyle:checkstyle, which is the command for running checkstyle 运行mvn checkstyle:checkstyle,这是运行checkstyle的命令

If you want to fail the build when there is a checkstyle violation in your project, then this is not the command. 如果您希望在项目中存在检查样式违规时使构建失败,那么这不是命令。 As shown at https://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html , this will just generate a file report and not fail the build if there are checkstyle violations in your project. https://maven.apache.org/plugins/maven-checkstyle-plugin/checkstyle-mojo.html所示,这只会生成一个文件报告,如果项目中存在checkstyle违规,则不会使构建失败。

For this purpose they recommend checkstyle:check and https://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html#Checking_for_Violations_as_Part_of_the_Build shows an example on how to configure the it for your custom parameters. 为此,他们建议使用checkstyle:checkhttps://maven.apache.org/plugins/maven-checkstyle-plugin/usage.html#Checking_for_Violations_as_Part_of_the_Build显示如何为自定义参数配置它的示例。

I don't want to copy all my configurations from these dependencies 我不想从这些依赖项中复制所有配置

You should be able to use the embedded configuration just like sun and google configurations which are embedded in checkstyle. 您应该能够使用嵌入式配置,就像嵌入在checkstyle中的sun和google配置一样。 Just add it as a dependency and specify the config location, like /my/path/my_config.xml from the root of the dependency like you would loading a resource. 只需将其添加为依赖项并指定配置位置,例如来自依赖项根目录的/my/path/my_config.xml ,就像加载资源一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM