Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict imports with maven enforcer #1808

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 42 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-SNAPSHOT</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,39 @@
<goal>enforce</goal>
</goals>
</execution>
<execution>
<id>ban-transitive-imports</id>
<phase>process-sources</phase>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<RestrictImports>
<includeTestCode>true</includeTestCode>
<!-- Disallow all imports except explicitly
allowed -->
<reason>Disallow transitive dependencies</reason>
<bannedImports>
<bannedImport>**</bannedImport>
</bannedImports>
<allowedImports>
<!-- Allow oshi itself :-) -->
<allowedImport>oshi.**</allowedImport>
<!-- Allow core Java usages -->
<allowedImport>java.**</allowedImport>
<!-- Allow known dependencies -->
<allowedImport>com.sun.jna.**</allowedImport>
<allowedImport>org.slf4j.**</allowedImport>
<allowedImport>org.junit.jupiter.api.**</allowedImport>
<allowedImport>org.hamcrest.**</allowedImport>
</allowedImports>
<!-- No restrictions on oshi-demo -->
<exclusion>oshi.demo.**</exclusion>
</RestrictImports>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down