Use maven transitive dependency in build

Viewed 165

Is there a way to use the transitive dependency of some maven module instead using the default maven lib version? For example:

My project has a dependency on qulice-maven-plugin, which depends on qulice-checkstyle, which depends on 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.

If I run mvn checkstyle:checkstyle, which is the command for running checkstyle, it loads a default checkstyle version and uses its default configuration. 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.

Is there a way of doing this?

1 Answers

If I run mvn checkstyle:checkstyle it loads a default checkstyle version

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.

run mvn checkstyle:checkstyle, which is the command for running 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.

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.

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

Related