spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.51k stars 40.53k forks source link

Automatically filter `additional-spring-configuration-metadata.json` from Spring Boot-built archives #27430

Open wangliang181230 opened 3 years ago

wangliang181230 commented 3 years ago

Exclude additional-spring-configuration-metadata.json from the jars. This file is not required.

图片

bclozel commented 3 years ago

This file is packaged with your project to provide additional information to developers when working with your library, as explained in our reference documentation.

Not packaging it with the library would make that file useless.

bclozel commented 3 years ago

@wilkinsona pointed out that this information is indeed merged in the main metadata file.

I’m not sure how we can prevent this file from being packaged with the library. Is there anything we can do here? Maybe document how to filter out this file in the build?

wangliang181230 commented 3 years ago

Can put the additional-spring-configuration-metadata.json in the src/main/xxx directory? Not the /src/main/resources/META-INF directory.

wangliang181230 commented 3 years ago

Outside the /src/main/resources directory, I think it will not be packaged into the library.

bclozel commented 3 years ago

I'm not sure the annotation processor will be able to find these files if they're not shipped as resources.

wangliang181230 commented 3 years ago

Can the Maven plugin merge the metadata?

wangliang181230 commented 3 years ago

@bclozel The maven-jar-plugin can exclude additional, and is merged to the main metadata.

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <excludes>
                    <exclude>**/META-INF/additional-spring-configuration-metadata.json</exclude>
                </excludes>
            </configuration>
        </plugin>
    </plugins>
</build>

图片

snicoll commented 3 years ago

@wangliang181230 using the maven plugin to process the metadata would significantly decrease the developer experience. Using an annotation processor for this is the right call IMO and we really need the additional file to be on the classpath to process it. You are right that the file is, strictly speaking for Spring Boot, not used at runtime but I wouldn't be surprised if third party tools were relying on it. Configuring the maven-jar-plugin is one option if you really care about the duplicate.

Flagging for team attention to get more feedback from the team.

wilkinsona commented 3 years ago

I think it would be nice to avoid bundling the additional metadata file by default if we can.

It would be straightforward in our own build, but I'm not sure it's possible to do it automatically for users while using a location beneath src/main/resources. They could be building a shared module without our Maven or Gradle plugins so we don't have a chance to filter things.

The only other option that I can think of is to use a location outside src/main/resources for the metadata as suggested above. I wonder about the additional complexity of this, though, and the possible impact on up-to-date checks and incremental compilation with Gradle.

wilkinsona commented 3 years ago

We're going to update the Maven and Gradle plugins to filter out the file automatically. We'll also update the documentation to suggest that anyone building a library without our plugins configures their build to do the same.