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

Add build cache for formatter/impsort/enforcer #38399

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .mvn/extensions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<extension>
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<version>1.18.1</version>
<version>1.20</version>
</extension>
<extension>
<groupId>com.gradle</groupId>
<artifactId>common-custom-user-data-maven-extension</artifactId>
<version>1.12.2</version>
<version>1.12.5</version>
</extension>
</extensions>
278 changes: 267 additions & 11 deletions independent-projects/parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-java-version</id>
<id>enforce-java-maven-prerequisites</id>
<goals>
<goal>enforce</goal>
</goals>
Expand All @@ -150,16 +150,6 @@
</message>
<version>${jdk.min.version}</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
<execution>
<id>enforce-maven-version</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<message>To build this project Maven ${maven.min.version} (or greater) is required.
Please install it.
Expand Down Expand Up @@ -414,6 +404,11 @@
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<configuration>
<!-- You can debug caching by adding -Dorg.slf4j.simpleLogger.log.gradle.goal.cache=debug to the command line -->
<!-- More information about this configuration:
https://docs.gradle.com/enterprise/maven-extension/api/com/gradle/maven/extension/api/cache/MojoMetadataProvider.Context.html
https://www.gradle.com/schema/gradle-enterprise-maven-project.xsd
-->
<gradleEnterprise xmlns="https://www.gradle.com/gradle-enterprise-maven-project">
<normalization>
<systemProperties>
Expand Down Expand Up @@ -696,6 +691,267 @@
</cacheableBecause>
</outputs>
</plugin>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<inputs>
<fileSets>
<fileSet>
<name>sourceDirectory</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
<fileSet>
<name>testSourceDirectory</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
<fileSet>
<name>directories</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
</fileSets>
<properties>
<property>
<name>includes</name>
</property>
<property>
<name>excludes</name>
</property>
<property>
<name>compilerSource</name>
</property>
<property>
<name>compilerCompliance</name>
</property>
<property>
<name>compilerTargetPlatform</name>
</property>
<property>
<name>lineEnding</name>
</property>
<property>
<name>configFile</name>
</property>
<property>
<name>configJsFile</name>
</property>
<property>
<name>configHtmlFile</name>
</property>
<property>
<name>configXmlFile</name>
</property>
<property>
<name>configJsonFile</name>
</property>
<property>
<name>configCssFile</name>
</property>
<property>
<name>skipFormattingCache</name>
</property>
<property>
<name>skipJavaFormatting</name>
</property>
<property>
<name>skipJsFormatting</name>
</property>
<property>
<name>skipHtmlFormatting</name>
</property>
<property>
<name>skipXmlFormatting</name>
</property>
<property>
<name>skipJsonFormatting</name>
</property>
<property>
<name>skipCssFormatting</name>
</property>
<property>
<name>skipFormatting</name>
</property>
<property>
<name>useEclipseDefaults</name>
</property>
<property>
<name>javaExclusionPattern</name>
</property>
<property>
<name>removeTrailingWhitespace</name>
</property>
<property>
<name>includeResources</name>
</property>
</properties>
<ignoredProperties>
<ignore>project</ignore>
<ignore>targetDirectory</ignore>
<ignore>basedir</ignore>
</ignoredProperties>
</inputs>
<nestedProperties>
<property>
<name>encoding</name>
<inputs>
<properties>
<property>
<name>displayName</name>
</property>
</properties>
</inputs>
</property>
</nestedProperties>
<outputs>
<directories>
<directory>
<name>cachedir</name>
</directory>
</directories>
<cacheableBecause>check should only run when inputs change
</cacheableBecause>
</outputs>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<inputs>
<fileSets>
<fileSet>
<name>sourceDirectory</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
<fileSet>
<name>testSourceDirectory</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
<fileSet>
<name>directories</name>
<normalization>
<ignoreEmptyDirectories>true</ignoreEmptyDirectories>
</normalization>
</fileSet>
</fileSets>
<properties>
<property>
<name>sourceEncoding</name>
</property>
<property>
<name>skip</name>
</property>
<property>
<name>staticGroups</name>
</property>
<property>
<name>groups</name>
</property>
<property>
<name>staticAfter</name>
</property>
<property>
<name>joinStaticWithNonStatic</name>
</property>
<property>
<name>includes</name>
</property>
<property>
<name>excludes</name>
</property>
<property>
<name>removeUnused</name>
</property>
<property>
<name>treatSamePackageAsUnused</name>
</property>
<property>
<name>breadthFirstComparator</name>
</property>
<property>
<name>lineEnding</name>
</property>
<property>
<name>compliance</name>
</property>
</properties>
<ignoredProperties>
<ignore>project</ignore>
<ignore>plugin</ignore>
</ignoredProperties>
</inputs>
<outputs>
<!-- For now we don't want to output the cachedir as it contains absolute paths
See https://github.com/revelc/impsort-maven-plugin/pull/87
<directories>
<directory>
<name>cachedir</name>
</directory>
</directories>
-->
<cacheableBecause>check should only run when inputs change
</cacheableBecause>
</outputs>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<inputs>
<fileSets>
<fileSet>
<name>foo</name>
<paths>
<path>${project.basedir}/pom.xml</path>
</paths>
<normalization>RELATIVE_PATH</normalization>
</fileSet>
Comment on lines +907 to +914
Copy link
Member Author

@gsmet gsmet Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jprinet I used your proposal except I restricted it to the pom file as really that's what all our enforcer rules are checking.

That being said, I have two questions:

  • are the plugin dependencies taken into account in the cache key? We have rules that are inside a jar declared as a dependency. If the jar changes, will the cache be invalidated?
  • some of our rules are inspecting the transitive dependencies so I would need to somehow include the classpath into the cache key. Is there a way to do that when the plugin doesn't expose it?

I saw the following for the kotlin-maven-plugin but these are properties from the plugin:

<fileSet>
    <name>classpath</name>
    <normalization>COMPILE_CLASSPATH</normalization>
</fileSet>
<fileSet>
    <name>testClasspath</name>
    <normalization>COMPILE_CLASSPATH</normalization>
</fileSet>

Is there a way to include the classpath jars into the cache key?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are the plugin dependencies taken into account in the cache key? We have rules that are inside a jar declared as a dependency. If the jar changes, will the cache be invalidated?

There is no default input, the plugin has to define it which is not the case apparently for the enforcer plugin

some of our rules are inspecting the transitive dependencies so I would need to somehow include the classpath into the cache key. Is there a way to do that when the plugin doesn't expose it?

The only way would be with the programmatic approach, nothing you can do with the XML configuration afaik.
We are doing that for the Quarkus build caching extension.

</fileSets>
<properties>
<property>
<name>skip</name>
</property>
<property>
<name>fail</name>
</property>
<property>
<name>failFast</name>
</property>
<property>
<name>failIfNoRules</name>
</property>
<property>
<name>rules</name>
</property>
<property>
<name>rules</name>
</property>
<property>
<name>rulesToExecute</name>
</property>
<property>
<name>rulesToSkip</name>
</property>
<property>
<name>ignoreCache</name>
</property>
</properties>
<ignoredProperties>
<ignore>mojoExecution</ignore>
<ignore>session</ignore>
<ignore>project</ignore>
</ignoredProperties>
</inputs>
<outputs>
<cacheableBecause>check should only run when inputs change</cacheableBecause>
</outputs>
</plugin>
</plugins>
</gradleEnterprise>
</configuration>
Expand Down
Loading