Skip to content

Spotless-specific: package-info.java with multiple annotations loses "package" statement #910

Closed

Description

@ZachCallear

In the attached test project, which is a barebones Gradle Wrapper setup, using the latest versions of the Spotless Gradle plugin (8.6.0), Prettier (3.8.3), and prettier-java (2.9.6), running ./gradlew spotlessApply results in src/main/java/testpackagebad/package-info.java getting incorrectly reformatted to lose its package and annotation lines.

Before:

@SomeAnnotation1
@SomeAnnotation2
package testpackagebad;

import foo.SomeAnnotation1;
import foo.SomeAnnotation2;

After:

import foo.SomeAnnotation1;
import foo.SomeAnnotation2;

The very similar src/main/java/testpackagegood/package-info.java file, having the following contents (two annotations instead of one), is not affected:

@SomeAnnotation1
package testpackagegood;

import foo.SomeAnnotation1;

It's possible this is something to be reported to the Spotless project, but I'm unsure. In playing around with it, it seems to start with version 2.9.1 of prettier-java, although it bears more investigation.

test-gradle-project.zip

Activity

  1. jtkiesel commented on May 28, 2026

    @jtkiesel
    Contributor

    This seems to be caused by this plugin attempting to produce a syntactically invalid Java output by (for some reason) moving the import statements above the package declaration as soon as there's a 2nd annotation added to the package declaration. Spotless is most likely confused by the structure of its output.

    I'll look into it further. Thank you for reporting this bug!

  2. ZachCallear commented on May 28, 2026

    @ZachCallear
    Author

    Thank you for your speedy fix of this and for Prettier Java!

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

      Issue actions