Skip to content

Spotless replaces package-info.java's javadoc with the license #1

Closed
@nedtwigg

Description

@nedtwigg

If Spotless has a licenseHeader specified, it replaces everything between the top of the file and the package statement with the license. This works for regular classes, but it doesn't work for package-info.java files.

As a workaround, you can do this:

java {
    target project.fileTree(project.rootDir) {
        include '**/*.java'
        exclude '**/package-info.java'
        exclude 'spotless.license.java'
    }
    ... (the rest of the config)
}

Spotless' default settings should play nicely with package-info.java, but at the moment it's not a big enough problem for me to actually fix. If this is an actual problem for you, reply to this issue and I'll actually fix it.

Activity

opentest4j

opentest4j commented on Dec 10, 2015

@opentest4j

We (the JUnit Lambda team) would love to see some sort of flag to allow package-info.java files to contain custom Javadoc (/** ... */) without having it automatically stripped out by Spotless.

nedtwigg

nedtwigg commented on Dec 10, 2015

@nedtwigg
MemberAuthor

I'm happy to take a PR for this, or I'll have a bugfix by Monday. In the meantime, you can copy-paste the little "target" snippet above as a workaround.

sbrannen

sbrannen commented on Dec 10, 2015

@sbrannen

Thanks, @nedtwigg!

No rush on the fix. For the time being, I've already used the explicit exclude approach as can be seen here: https://github.com/ota4j-team/opentest4j/blob/master/build.gradle

nedtwigg

nedtwigg commented on Dec 17, 2015

@nedtwigg
MemberAuthor

Fixed in 1.3.2.

sbrannen

sbrannen commented on Dec 17, 2015

@sbrannen

That does the job.

Thanks!

sbrannen

sbrannen commented on Dec 17, 2015

@sbrannen

By the way, JUnit Lambda (a.k.a., JUnit 5) also uses Spotless... in case you want to list it in the README as well.

https://github.com/junit-team/junit-lambda/blob/master/build.gradle

nedtwigg

nedtwigg commented on Dec 17, 2015

@nedtwigg
MemberAuthor

The formatter runs in steps - indent, then header, then eclipse, etc. The old workaround disabled all steps in package-info, but in 1.3.2 it disables only the license-header step, so you still get checking for trailing white space, eclipse formatter, etc. Probably one of the other steps is disagreeing with your package-info.

Thanks for junit 5 info, I'll definitely add that!

On Dec 17, 2015, at 5:27 AM, Sam Brannen notifications@github.com wrote:

I removed the "target" configuration and upgraded to 1.3.2, but it is failing as follows.

Download https://plugins.gradle.org/m2/com/diffplug/gradle/spotless/spotless/1.3.2/spotless-1.3.2.pom
Download https://plugins.gradle.org/m2/com/diffplug/gradle/spotless/spotless/1.3.2/spotless-1.3.2.jar

...

:spotlessJavaCheck FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':spotlessJavaCheck'.

    Format violations were found. Run 'gradlew spotlessApply' to fix them.
    src/main/java/org/opentest4j/package-info.java
    What am I missing?


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sbrannen@nedtwigg@opentest4j

        Issue actions

          Spotless replaces package-info.java's javadoc with the license · Issue #1 · diffplug/spotless