Skip to content

Commit

Permalink
Restrict imports with maven enforcer (#1808)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Dec 3, 2021
1 parent 8fc6ee5 commit abd889f
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<url>github:ssh://oshi.github.io/oshi/</url>
</site>
<snapshotRepository>
<id>ossrh</id>
<id>ossrh-snapshot</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
Expand Down Expand Up @@ -107,6 +107,7 @@
<maven-deploy-plugin.version>3.0.0-M1</maven-deploy-plugin.version>
<nexus-staging-plugin.version>1.6.8</nexus-staging-plugin.version>
<maven-enforcer-plugin.version>3.0.0</maven-enforcer-plugin.version>
<restrict-imports-enforcer-rule.version>2.0.0</restrict-imports-enforcer-rule.version>
<maven-gpg-plugin.version>3.0.1</maven-gpg-plugin.version>
<maven-install-plugin.version>3.0.0-M1</maven-install-plugin.version>
<maven-resources-plugin.version>3.2.0</maven-resources-plugin.version>
Expand Down Expand Up @@ -198,6 +199,13 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<dependencies>
<dependency>
<groupId>de.skuzzle.enforcer</groupId>
<artifactId>restrict-imports-enforcer-rule</artifactId>
<version>${restrict-imports-enforcer-rule.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -629,6 +637,38 @@
<goal>enforce</goal>
</goals>
</execution>
<execution>
<id>ban-transitive-imports</id>
<phase>process-sources</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<RestrictImports>
<reason>Disallow dependencies not on module path</reason>
<includeTestCode>true</includeTestCode>
<bannedImports>
<!-- Disallow all imports except explicitly allowed -->
<bannedImport>**</bannedImport>
</bannedImports>
<allowedImports>
<!-- Allow oshi itself :-) -->
<allowedImport>oshi.**</allowedImport>
<!-- Allow core Java usage -->
<allowedImport>java.**</allowedImport>
<!-- Allow known dependencies -->
<allowedImport>com.sun.jna.**</allowedImport>
<allowedImport>org.slf4j.**</allowedImport>
<allowedImport>org.junit.jupiter.api.**</allowedImport>
<allowedImport>static org.hamcrest.**</allowedImport>
</allowedImports>
<!-- No restrictions on oshi-demo -->
<exclusion>oshi.demo.**</exclusion>
</RestrictImports>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down

0 comments on commit abd889f

Please sign in to comment.