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

Maven Plugin global ratchetFrom not working with multiple formatters #664

Closed
stephen-smith opened this issue Aug 9, 2020 · 3 comments
Closed

Comments

@stephen-smith
Copy link

stephen-smith commented Aug 9, 2020

Maven Plugin global ratchetFrom not working with multiple formatters

I have a "global" ratchetFrom like <configuration><ratchetFrom>A_SHA_HASH</ratchetFrom>... and both a "java" and a "formats" section. Under the "formats" there are two "format"s. All 3 use using prettier, with different plugins, parsers, options, and (non-overlapping) includes.

In the above case, I got an error from spotless:check for a file that that not been changed since the ratchet point. I thought that it might just be a problem with prettier or one of the sub-configurations. So, I copied the ratchetFrom into the format that covered the file it was complaining about. The first error went away, but I got an error from the other format, about another file that has not been changes since the ratchet point. I repeated the process, but ended up having to copy the ratchetFrom into both "format" elements and the "java" element.

Finally, spotless behaved as expected. I then removed the global ratchedFrom, and it was still successful.

The documentation clearly says ratchetFrom is supposed to work "globally", and may (but is not required to be) specified on each format as well: https://github.com/diffplug/spotless/tree/a1b5e90a9d0788bcc5a651ae424deb06330a92b1/plugin-maven#how-can-i-enforce-formatting-gradually-aka-ratchet

  • gradle or maven version: Maven 3.6.0
  • spotless version: 2.0.1
  • operating system and version: Debian GNU+Linux 10.5
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible (TBD)
  • copy-paste the full content of any console errors emitted by gradlew spotless[Apply/Check] --stacktrace (TBD)

I need to reproduce in a public repository. I'm not comfortable even sharing the error messages generated out of our propritary repository. So, the copy-paste requirements above are TBD.

I hope it won't take long to publicly reproduce.

@stephen-smith
Copy link
Author

Working local ratchetFrom: https://gitlab.com/bss03/spotless-664/-/tree/07f9a922ed539bca8665148a2bb621954fc76aaa

Non-working global ratchetFrom: https://gitlab.com/bss03/spotless-664/-/tree/101d59d9691bf2e99761b2797072b9dac9ede13c

mvn -X verify output:

[INFO] --- spotless-maven-plugin:2.0.1:check (default) @ example ---        
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=62840, ConflictMarker.markTime=23825, ConflictMarker.nodeCount=22, ConflictIdSorter.graphTime=
22954, ConflictIdSorter.topsortTime=17974, ConflictIdSorter.conflictIdCount=16, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=332624, Con
flictResolver.conflictItemCount=22, DefaultDependencyCollector.collectTime=17369077, DefaultDependencyCollector.transformTime=482578}                          
[DEBUG] com.diffplug.spotless:spotless-maven-plugin:jar:2.0.1:                                                                                                 
[DEBUG]    com.diffplug.spotless:spotless-lib:jar:2.1.0:runtime                                                                                               
[DEBUG]    com.diffplug.spotless:spotless-lib-extra:jar:2.1.0:runtime                                                                                         
[DEBUG]       com.googlecode.concurrent-trees:concurrent-trees:jar:2.6.1:runtime                                                                              
[DEBUG]       org.codehaus.groovy:groovy-xml:jar:3.0.3:runtime                                                                                                
[DEBUG]          org.codehaus.groovy:groovy:jar:3.0.3:runtime                                                                                                  
[DEBUG]    org.codehaus.plexus:plexus-resources:jar:1.0.1:runtime
[DEBUG]       org.codehaus.plexus:plexus-utils:jar:3.0.8:runtime                                                                                               
[DEBUG]       org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-9-stable-1:runtime
[DEBUG]          junit:junit:jar:3.8.1:runtime                                                                                                                 
[DEBUG]          classworlds:classworlds:jar:1.1-alpha-2:runtime
[DEBUG]    com.diffplug.durian:durian-core:jar:1.2.0:runtime                                                                                          
[DEBUG]    com.diffplug.durian:durian-collect:jar:1.2.0:runtime                                                                                               
[DEBUG]    org.eclipse.jgit:org.eclipse.jgit:jar:5.8.0.202006091008-r:runtime
[DEBUG]       com.googlecode.javaewah:JavaEWAH:jar:1.1.7:runtime                                                                                              
[DEBUG]       org.slf4j:slf4j-api:jar:1.7.2:runtime                                                                                                           
[DEBUG] Created new class realm plugin>com.diffplug.spotless:spotless-maven-plugin:2.0.1                                                                      
[DEBUG] Importing foreign packages into class realm plugin>com.diffplug.spotless:spotless-maven-plugin:2.0.1                                                  
[DEBUG]   Imported:  < maven.api                                                                                                                              
[DEBUG] Populating class realm plugin>com.diffplug.spotless:spotless-maven-plugin:2.0.1                                                                       
[DEBUG]   Included: com.diffplug.spotless:spotless-maven-plugin:jar:2.0.1                                                                                     
[DEBUG]   Included: com.diffplug.spotless:spotless-lib:jar:2.1.0                                                                                              
[DEBUG]   Included: com.diffplug.spotless:spotless-lib-extra:jar:2.1.0                                                                                        
[DEBUG]   Included: com.googlecode.concurrent-trees:concurrent-trees:jar:2.6.1                                                                                
[DEBUG]   Included: org.codehaus.groovy:groovy-xml:jar:3.0.3                                                                                                   
[DEBUG]   Included: org.codehaus.groovy:groovy:jar:3.0.3              
[DEBUG]   Included: org.codehaus.plexus:plexus-resources:jar:1.0.1                                                                                             
[DEBUG]   Included: org.codehaus.plexus:plexus-utils:jar:3.0.8      
[DEBUG]   Included: junit:junit:jar:3.8.1                                      
[DEBUG]   Included: com.diffplug.durian:durian-core:jar:1.2.0  
[DEBUG]   Included: com.diffplug.durian:durian-collect:jar:1.2.0               
[DEBUG]   Included: org.eclipse.jgit:org.eclipse.jgit:jar:5.8.0.202006091008-r
[DEBUG]   Included: com.googlecode.javaewah:JavaEWAH:jar:1.1.7                                                                                                
[DEBUG] Configuring mojo com.diffplug.spotless:spotless-maven-plugin:2.0.1:check from plugin realm ClassRealm[plugin>com.diffplug.spotless:spotless-maven-plugi
n:2.0.1, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@55054057]                                                                                     
[DEBUG] Configuring mojo 'com.diffplug.spotless:spotless-maven-plugin:2.0.1:check' with basic configurator -->                                                
[DEBUG]   (f) baseDir = /home/bss/git/spotless-664                                                                                                            
[DEBUG]   (f) buildDir = /home/bss/git/spotless-664/target                                                                                                    
[DEBUG]   (f) encoding = UTF-8                                                                                                                                
[DEBUG]   (s) trimTrailingWhitespace = com.diffplug.spotless.maven.generic.TrimTrailingWhitespace@348ad293
[DEBUG]   (s) endWithNewline = com.diffplug.spotless.maven.generic.EndWithNewline@30f74e79
[DEBUG]   (f) order = java,javax,org,                                                                                                                         
[DEBUG]   (s) importOrder = com.diffplug.spotless.maven.java.ImportOrder@69923ac3                                                                             
[DEBUG]   (s) removeUnusedImports = com.diffplug.spotless.maven.java.RemoveUnusedImports@1f1ff879                                                             
[DEBUG]   (f) version = 1.7                                                 
[DEBUG]   (f) style = GOOGLE                                                                                                                                   [DEBUG]   (s) googleJavaFormat = com.diffplug.spotless.maven.java.GoogleJavaFormat@73d60e76
[DEBUG]   (f) java = com.diffplug.spotless.maven.java.Java@24f870ee             
[DEBUG]   (f) lineEndings = GIT_ATTRIBUTES                           
[DEBUG]   (f) ratchetFrom = 6697                                                                                                                              
[DEBUG]   (f) repositories = [tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default, releases+snapshots), central (https://repo.m
aven.apache.org/maven2, default, releases)]                               
[DEBUG]   (f) repositorySystemSession = org.eclipse.aether.DefaultRepositorySystemSession@32177fa5
[DEBUG]   (f) skip = false                                                                                                                                     
[DEBUG] -- end configuration --                                 
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=33424, ConflictMarker.markTime=22152, ConflictMarker.nodeCount=11, ConflictIdSorter.graphTime=
10049, ConflictIdSorter.topsortTime=14177, ConflictIdSorter.conflictIdCount=10, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=396614, Con
flictResolver.conflictItemCount=10, DefaultDependencyCollector.collectTime=13849798, DefaultDependencyCollector.transformTime=491846}                         
[DEBUG] Resolved artifact: com.google.googlejavaformat:google-java-format:jar:1.7 < central (https://repo.maven.apache.org/maven2, default, releases)         
[DEBUG] Resolved artifact: com.google.guava:guava:jar:27.0.1-jre < central (https://repo.maven.apache.org/maven2, default, releases)                          
[DEBUG] Resolved artifact: com.google.guava:failureaccess:jar:1.0.1 < central (https://repo.maven.apache.org/maven2, default, releases)                       
[DEBUG] Resolved artifact: com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava < central (https://repo.maven.apache.org/maven2, def
ault, releases)                                                                                                                                               
[DEBUG] Resolved artifact: com.google.code.findbugs:jsr305:jar:3.0.2 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default, rel
eases+snapshots)                                                      
[DEBUG] Resolved artifact: org.checkerframework:checker-qual:jar:2.5.2 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default, r
eleases+snapshots)                                              
[DEBUG] Resolved artifact: com.google.errorprone:error_prone_annotations:jar:2.2.0 < central (https://repo.maven.apache.org/maven2, default, releases)
[DEBUG] Resolved artifact: com.google.j2objc:j2objc-annotations:jar:1.1 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default,
releases+snapshots)                                                         
[DEBUG] Resolved artifact: org.codehaus.mojo:animal-sniffer-annotations:jar:1.17 < central (https://repo.maven.apache.org/maven2, default, releases)           
[DEBUG] Resolved artifact: com.google.errorprone:javac-shaded:jar:9+181-r4173-1 < central (https://repo.maven.apache.org/maven2, default, releases)            
[DEBUG] Dependency collection stats: {ConflictMarker.analyzeTime=20710, ConflictMarker.markTime=19457, ConflictMarker.nodeCount=11, ConflictIdSorter.graphTime=
9007, ConflictIdSorter.topsortTime=15018, ConflictIdSorter.conflictIdCount=10, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=138944, Conf
lictResolver.conflictItemCount=10, DefaultDependencyCollector.collectTime=309519, DefaultDependencyCollector.transformTime=214268}                            
[DEBUG] Resolved artifact: com.google.googlejavaformat:google-java-format:jar:1.7 < central (https://repo.maven.apache.org/maven2, default, releases)         
[DEBUG] Resolved artifact: com.google.guava:guava:jar:27.0.1-jre < central (https://repo.maven.apache.org/maven2, default, releases)                          
[DEBUG] Resolved artifact: com.google.guava:failureaccess:jar:1.0.1 < central (https://repo.maven.apache.org/maven2, default, releases)                       
[DEBUG] Resolved artifact: com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava < central (https://repo.maven.apache.org/maven2, def
ault, releases)                                                  
[DEBUG] Resolved artifact: com.google.code.findbugs:jsr305:jar:3.0.2 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default, rel
eases+snapshots)                                                                           
[DEBUG] Resolved artifact: org.checkerframework:checker-qual:jar:2.5.2 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default, r
eleases+snapshots)                                              
[DEBUG] Resolved artifact: com.google.errorprone:error_prone_annotations:jar:2.2.0 < central (https://repo.maven.apache.org/maven2, default, releases)
[DEBUG] Resolved artifact: com.google.j2objc:j2objc-annotations:jar:1.1 < tgcs-nexus (http://tgcsnexus.rtptgcs.com:28081/repository/tgcs-maven-group, default,
releases+snapshots)                                                          
[DEBUG] Resolved artifact: org.codehaus.mojo:animal-sniffer-annotations:jar:1.17 < central (https://repo.maven.apache.org/maven2, default, releases)          
[DEBUG] Resolved artifact: com.google.errorprone:javac-shaded:jar:9+181-r4173-1 < central (https://repo.maven.apache.org/maven2, default, releases)           
[DEBUG] readpipe [git, --version],/usr/bin                                                                                                                    
[DEBUG] readpipe may return 'git version 2.20.1'                                                                                                              
[DEBUG] remaining output:                                                                                                                                     
                                                                                                                                                              
[DEBUG] readpipe [git, config, --system, --edit],/usr/bin                                                                                                     
[DEBUG] readpipe may return '/etc/gitconfig'                                                                                                                  
[DEBUG] remaining output:                                                                                                                                     
                                                                                                                                                              
[DEBUG] file=/home/bss/.gitconfig, create new FileSnapshot: lastRead=2020-08-08 20:38:35.257090000, lastModified=2019-06-21 06:07:37.637952000, size=387, fileK
ey=(dev=43,ino=6436994)                                               
[DEBUG] file=/home/bss/git/spotless-664/.git/config, create new FileSnapshot: lastRead=2020-08-08 20:38:35.264170000, lastModified=2020-08-08 20:36:38.02741400
0, size=262, fileKey=(dev=43,ino=29499399)                          
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE                                           
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.584 s                                                   
[INFO] Finished at: 2020-08-08T20:38:35-05:00                                                                                                                 
[INFO] ------------------------------------------------------------------------                                                                                
[ERROR] Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.0.1:check (default) on project example: The following files had format violations:
[ERROR]     src/main/java/HelloWorld.java                                                                                                                     
[ERROR]         @@ -1 +1,5 @@                                                                                                                                 
[ERROR]         -final·class·HelloWorld{public·static·void·main(final·String[]·args)throws·Exception{System.out.println("Hello,·World!");}}                   
[ERROR]         +final·class·HelloWorld·{                                                                                                                     
[ERROR]         +··public·static·void·main(final·String[]·args)·throws·Exception·{                        
[ERROR]         +····System.out.println("Hello,·World!");                                 
[ERROR]         +··}                                                                                                                                          
[ERROR]         +}                                                                                                                                            
[ERROR] Run 'mvn spotless:apply' to fix these violations.                                                                                                     
[ERROR] -> [Help 1]                                                         
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.diffplug.spotless:spotless-maven-plugin:2.0.1:check (default) on project example: The following files had format violations:                                           
    src/main/java/HelloWorld.java                                               
        @@ -1 +1,5 @@                                                
        -final·class·HelloWorld{public·static·void·main(final·String[]·args)throws·Exception{System.out.println("Hello,·World!");}}                           
        +final·class·HelloWorld·{                                                                                                                              
        +··public·static·void·main(final·String[]·args)·throws·Exception·{
        +····System.out.println("Hello,·World!");                                                 
        +··}                                                                                                                                                   
        +}                                                      
Run 'mvn spotless:apply' to fix these violations.                                                                                                              
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)                                                                        
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)                                                                       
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)                                                                       
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)                                              
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)                                               
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)                                  
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)                                                               
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)                                                                                         
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)                                                                                           
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)                                                                                       
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)                                                                                                 
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)                                                                 
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)                                                         
    at java.lang.reflect.Method.invoke (Method.java:566)                                                                                                       
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)                                                                    
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)                                                                           
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)                                                                 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)                                                                             
Caused by: org.apache.maven.plugin.MojoExecutionException: The following files had format violations:                                                         
    src/main/java/HelloWorld.java                                                                                                                              
        @@ -1 +1,5 @@                                            
        -final·class·HelloWorld{public·static·void·main(final·String[]·args)throws·Exception{System.out.println("Hello,·World!");}}                            
        +final·class·HelloWorld·{                                                          
        +··public·static·void·main(final·String[]·args)·throws·Exception·{                                                                                     
        +····System.out.println("Hello,·World!");               
        +··}                                                                                                                                          
        +}                                                                                                                                                    
Run 'mvn spotless:apply' to fix these violations.                            
    at com.diffplug.spotless.maven.SpotlessCheckMojo.process (SpotlessCheckMojo.java:66)                                                                      
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:142)                                                               
    at com.diffplug.spotless.maven.AbstractSpotlessMojo.execute (AbstractSpotlessMojo.java:127)                                                               
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)                                                     
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)                                                                       
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)                                                                       
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)                                                                       
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)                                              
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)                                               
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)                                 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)                                                                
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
    at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)                                                                                         
    at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
    at org.apache.maven.cli.MavenCli.execute (MavenCli.java:956)               
    at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:288)
    at org.apache.maven.cli.MavenCli.main (MavenCli.java:192)                  
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)  
    at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)                                                                
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)                                                         
    at java.lang.reflect.Method.invoke (Method.java:566)                                                                                                       
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)                                                                   
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)                                                                           
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)                                                                 
    at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)                                                                             
[ERROR]                                                                                                   
[ERROR]                                                                                   
[ERROR] For more information about the errors and possible solutions, please read the following articles:                                                     
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException                                                                      

@stephen-smith
Copy link
Author

Example doesn't even use multiple formatters. I'm guessing global ratchetFrom is just completely broken, but I'm not sure.

@nedtwigg
Copy link
Member

Thanks for reporting, fixed in plugin-maven 2.0.2 by #666.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants