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

Gradle plugin does not provided public constant for the productionRuntimeClasspath configuration #26686

Closed
ChristianCiach opened this issue May 27, 2021 · 5 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@ChristianCiach
Copy link

ChristianCiach commented May 27, 2021

When using the gradle plugin org.springframework.boot, it creates a configuration called developmentOnly and also changes the configuration runtimeClasspath to extend from developmentOnly.

Minimal example:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.5.0'
}

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
    developmentOnly group: 'org.springframework.boot', name: 'spring-boot-devtools'
}

This effectively puts the devtools onto the runtime classpath, as can be verified by running ./gradlew -i dependencies --configuration runtimeClasspath.

We are building our projects as Docker images by using Google Jib. Jib blindly (but correctly) includes the complete runtimeClasspath into the image. This behavior is discussed here:

To exclude the devtools, there is an official jib extension: https://github.com/GoogleContainerTools/jib-extensions/tree/master/first-party/jib-spring-boot-extension-gradle . But this extension feels a bit cumbersome to use and really feels like a hacky workaround.

While researching other solutions to this issue, I've found out that the spring boot gradle plugin actually creates another gradle configuration called productionRuntimeClasspath that excludes the dependencies of the developmentOnly configuration. This is great and exactly what we need, because Jib can easily configured to use another configuration than runtimeClasspath.

Minimal example:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.5.0'
    id 'com.google.cloud.tools.jib' version '3.0.0'
}

dependencies {
    implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES)
}

dependencies {
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web'
    developmentOnly group: 'org.springframework.boot', name: 'spring-boot-devtools'
}

jib {
    configurationName = org.springframework.boot.gradle.plugin.SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_NAME
    from {
        image = 'amazoncorretto:16'
    }
    to {
        image = 'myimage'
    }
}

As you can see, I reference org.springframework.boot.gradle.plugin.SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_NAME as the configuration name that Jib should consume.

This works, because this is Groovy, and Groovy doesn't care about modifiers. In the source file at

, the constant is package private.

I hope that I could explain my use-case sufficiently. I think the constant PRODUCTION_RUNTIME_CLASSPATH_NAME should be made public. Other constants like BOM_COORDINATES are already public for (as I assume) similar reasons.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label May 27, 2021
@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label May 27, 2021
@philwebb philwebb changed the title Gradle plugin: Make SpringBootPlugin.PRODUCTION_RUNTIME_CLASSPATH_NAME public Gradle plugin does not provided public constant for the productionRuntimeClasspath configuration May 27, 2021
@philwebb philwebb added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels May 27, 2021
@philwebb philwebb added this to the 2.4.x milestone May 27, 2021
@philwebb philwebb modified the milestones: 2.4.x, 2.4.7 May 27, 2021
@philwebb
Copy link
Member

Thanks for the report. I agree that the constant should be public.

@ChristianCiach
Copy link
Author

Huh, that was surprisingly easy. One should keep in mind that this configuration is now public api, even though the plugin tried to hide it before:

Maybe the configuration productionRuntimeClasspath should even be properly documented now, maybe here: https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/htmlsingle/#reacting-to-other-plugins.java

Anyway, thank you for this quick response!

@philwebb philwebb reopened this May 27, 2021
@philwebb philwebb added the for: team-meeting An issue we'd like to discuss as a team to make progress label May 27, 2021
philwebb added a commit that referenced this issue May 27, 2021
Rename the now public constant for consistency with the JavaPlugin.

See gh-26686
@philwebb
Copy link
Member

I missed that we previously kept the configuration open. I've flagged this issue for further team discussion because I'd like a second opinion on the change.

@ChristianCiach
Copy link
Author

Alright, thanks so far! I again want to stress the fact that there are real use cases for this configuration. Jib is hardly the only tool that consumes the runtimeClasspath configuration but would be better off consuming productionRuntimeClasspath.

@philwebb philwebb self-assigned this Jun 7, 2021
@philwebb
Copy link
Member

We've decided to make the constant public but keep setVisible(false) so that the configuration isn't visible outside of the project it belongs to.

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

No branches or pull requests

3 participants