Skip to content

XML formatter config is sometimes not applied when running gradle --parallel #492

Closed
@epkanol

Description

@epkanol

At this moment, don't know if this is a gradle or spotless-plugin problem.

Sometimes, when running gradle --parallel, the configFile() setting is not applied, or is applied too late (after formatting has started in another thread)

Command line used from Jenkins is: gradle --parallel build check --info

05:26:04 ------------------------------------------------------------
05:26:04 Gradle 5.6.3
05:26:04 ------------------------------------------------------------
05:26:04 
05:26:04 Build time:   2019-10-18 00:28:36 UTC
05:26:04 Revision:     bd168bbf5d152c479186a897f2cea494b7875d13
05:26:04 
05:26:04 Kotlin:       1.3.41
05:26:04 Groovy:       2.5.4
05:26:04 Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
05:26:04 JVM:          1.8.0_231 (Oracle Corporation 25.231-b11)
05:26:04 OS:           Linux 3.10.0-1062.el7.x86_64 amd64
...
05:26:18 Downloading https://plugins.gradle.org/m2/com/diffplug/spotless/spotless-plugin-gradle/3.26.1/spotless-plugin-gradle-3.26.1.jar to XXXX
05:26:25 Downloading https://plugins.gradle.org/m2/com/diffplug/spotless/spotless-eclipse-base/3.2.1/spotless-eclipse-base-3.2.1.pom to XXXX
05:26:25 Downloading https://plugins.gradle.org/m2/com/diffplug/spotless/spotless-eclipse-wtp/3.15.1/spotless-eclipse-wtp-3.15.1.pom to XXXX

This is the spotless version:

classpath group: 'com.diffplug.spotless', name: 'spotless-plugin-gradle', version: '3.26.1'

This is the spotless configuration:

  spotless {
        java {
            googleJavaFormat('1.7')
            licenseHeaderFile file("$project.rootProject.projectDir/config/license.java")
        }
        format 'gradle', {
            target '**/*.gradle'
            trimTrailingWhitespace()
            indentWithSpaces(2)
            endWithNewline()
        }
        format 'xml', {
            target fileTree('.') {
                include '**/*.xml'
                exclude '**/build/**'
            }
            eclipseWtp('xml').configFile("$project.rootProject.projectDir/config/spotless.xml.prefs")
        }
    }

The xml prefs are the standard eclipse prefs:

user@host> cat config/spotless.xml.prefs
eclipse.preferences.version=1
indentationChar=space
indentationSize=2
lineWidth=200
user@host>

Error message (trimmed):

05:26:32 FAILURE: Build failed with an exception.
05:26:32 
05:26:32 * What went wrong:
05:26:32 Execution failed for task ':some-proj:spotlessXml'.
05:26:32 > The following files had format violations:
05:26:32       some-proj/path/some-file.xml
05:26:32           @@ -1,93 +1,117 @@
05:26:32            <?xml·version="1.0"·encoding="UTF-8"·standalone="no"?>
05:26:32           -<tag foo="value that is quite long and is likely to span several lines when formatted">
05:26:32           -··<!--·some comment·-->
05:26:32           -··<child-tag name="some-name"·value="123456789"·/>
05:26:32           +<tag
05:26:32           +\t\tname="value that is quite long and is likely to span several lines when formatted">
05:26:32           +\t\t<!--·some comment·-->
05:26:32           +\t\t<child-tag name="some-name"·value="123456789"·/>
...

It should be noted that the file was already formatted (as is seen in the above output, using two spaces) when this error was seen.
Something in either gradle or spotless causes the formatter to start formatting before it has received the correct service config (i.e. the contents of the property file).
I'd be happy to help to figure out what, if you could guide me into where to start looking (e.g. what are the entry points between the spotless plugin/ gradle configuration and the wtp formatter).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions