Illegal Transitive Dependency Check

This rule checks whether the code uses classes of another module through transitive dependencies.

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

de.is24.maven.enforcer.rules
ArtifactId

ArtifactId

illegal-transitive-dependency-check
Last Version

Last Version

1.7.4
Release Date

Release Date

Type

Type

jar
Description

Description

Illegal Transitive Dependency Check
This rule checks whether the code uses classes of another module through transitive dependencies.
Project URL

Project URL

https://github.com/ImmobilienScout24/illegal-transitive-dependency-check
Source Code Management

Source Code Management

https://github.com/ImmobilienScout24/illegal-transitive-dependency-check.git

Download illegal-transitive-dependency-check

How to add to project

<!-- https://jarcasting.com/artifacts/de.is24.maven.enforcer.rules/illegal-transitive-dependency-check/ -->
<dependency>
    <groupId>de.is24.maven.enforcer.rules</groupId>
    <artifactId>illegal-transitive-dependency-check</artifactId>
    <version>1.7.4</version>
</dependency>
// https://jarcasting.com/artifacts/de.is24.maven.enforcer.rules/illegal-transitive-dependency-check/
implementation 'de.is24.maven.enforcer.rules:illegal-transitive-dependency-check:1.7.4'
// https://jarcasting.com/artifacts/de.is24.maven.enforcer.rules/illegal-transitive-dependency-check/
implementation ("de.is24.maven.enforcer.rules:illegal-transitive-dependency-check:1.7.4")
'de.is24.maven.enforcer.rules:illegal-transitive-dependency-check:jar:1.7.4'
<dependency org="de.is24.maven.enforcer.rules" name="illegal-transitive-dependency-check" rev="1.7.4">
  <artifact name="illegal-transitive-dependency-check" type="jar" />
</dependency>
@Grapes(
@Grab(group='de.is24.maven.enforcer.rules', module='illegal-transitive-dependency-check', version='1.7.4')
)
libraryDependencies += "de.is24.maven.enforcer.rules" % "illegal-transitive-dependency-check" % "1.7.4"
[de.is24.maven.enforcer.rules/illegal-transitive-dependency-check "1.7.4"]

Dependencies

compile (8)

Group / Artifact Type Version
org.apache.maven.enforcer : enforcer-api jar 1.3.1
org.apache.maven : maven-project jar 2.0.9
org.apache.maven : maven-core jar 2.0.9
org.apache.maven : maven-artifact jar 2.0.9
org.apache.maven : maven-plugin-api jar 2.0.9
org.codehaus.plexus : plexus-container-default jar 1.5.5
org.apache.maven.shared : maven-dependency-tree jar 2.1
org.ow2.asm : asm-analysis jar 5.0.3

test (6)

Group / Artifact Type Version
junit : junit jar 4.11
org.apache.maven.enforcer : enforcer-rules test-jar 1.3.1
org.apache.maven.shared : maven-plugin-testing-harness jar 1.1
org.apache.maven.plugins : maven-enforcer-plugin maven-plugin 1.3.1
org.slf4j : slf4j-api jar 1.7.6
org.slf4j : slf4j-jdk14 jar 1.7.6

Project Modules

There are no modules declared in this project.

The 'Illegal' Transitive Dependency Check Rule

Build Status Coverage Status Maven Central

The IllegalTransitiveDependencyCheck is an additional rule for the maven-enforcer-plugin. The rule checks if all classes in a certain artifact references only classes that are provided by explicitly declared dependencies. Thus the rule will list (or complain about) all classes that are only available through transitive dependencies.

You can run the check by configuring the maven-enforcer-plugin to make use of the additional rule:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.3.1</version>
        <dependencies>
          <dependency>
            <groupId>de.is24.maven.enforcer.rules</groupId>
            <artifactId>illegal-transitive-dependency-check</artifactId>
            <version>1.7.4</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>enforce</id>
            <phase>verify</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <illegalTransitiveDependencyCheck implementation="de.is24.maven.enforcer.rules.IllegalTransitiveDependencyCheck">
                  <reportOnly>false</reportOnly>
                  <useClassesFromLastBuild>true</useClassesFromLastBuild>
                  <suppressTypesFromJavaRuntime>true</suppressTypesFromJavaRuntime>
                  <regexIgnoredClasses>
                      <regexIgnoredClass>javax\..+</regexIgnoredClass>
                      <regexIgnoredClass>org\.hibernate\..+</regexIgnoredClass>
                  </regexIgnoredClasses>
                  <listMissingArtifacts>false</listMissingArtifacts>
                </illegalTransitiveDependencyCheck>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

The rule itself can be configured to only report violations or even to signal the enforcer-plugin to break the build by specifying the attribute reportOnly. You may also exclude classes or packages from analysis by providing regex-patterns to parameter regexIgnoredClasses (e.g. my\.suppressed\.Type).

In addition to these exclusions types from packages javax.*,sun.*, jdk.*, org.* and com.sun.* that are available through the current Java runtime can be excluded automatically by setting parameter suppressTypesFromJavaRuntime.

By default the rule will resolve the currently analyzed artifact in the Maven repository. In case the enforcer-plugin runs in a phase compiled classes are available in the target folder (e.g. verify) artifact-resolving can be avoided by setting parameter useClassesFromLastBuild to true.

(Since version 1.7.4 the regexIngoredClasses filtering is also applied to the classes of the artifact currently analyzed. Thus direct dependencies of that classes will not be considered. See request #29)

If not only the classes but also the transitively used artifacts should be listed the parameter listMissingArtifacts can be set to true. Caution: This option is really slow!

Releases are available here in Maven's central repository.

de.is24.maven.enforcer.rules

ImmobilienScout24

Versions

Version
1.7.4
1.7.3
1.7.2
1.7.1
1.7
1.6
1.5
1.4
1.3
1.2
1.1