-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Make used Gradle SourceSet and Configuration configurable #1778
Comments
Can you explain this point a little more? It seems like you can either use the
This can be handled by the
I'm a little confused about this point. In reality it sounds like two projects IS what you want. They are separate artifacts and that are somewhat related. |
in this case the created images/initContainer are more of a build artifact rather than something warranting a project on its own. Examples where we have this for example are for Jenkins, Elastic and R3 Corda. We have around a dozen such projects and more coming. So what we would like to be possible to do is a Gradle plugin that takes that plugin project and jib and transparently setups an image/initContainer as part of the build. Important here are two things: the jib-related things cannot be on the runtime classpath and all logic to create the image can be put in a reusable fashion into a Gradle plugin.
e.g. if you want to have a project both as RPM and Image. For either we end up with slightly different runtime classpaths. Goes a bit into a similar direction as above where one could have one rather than three projects.
The baseImage is more of a Docker thing that should not leak into the Gradle runtime classpath. By using But this are just a few examples where one may would like to have a bit more flexilbity. I can imagine all kind of other use cases. The |
I think that supporting custom source sets and configurations will be very useful. Otherwise, any Gradle project that uses these features cannot use jib. Exactly my case right now. Please, provide these as jib's configuration options. |
A really important use case which at least sounds to be related is It basically seems like jib/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java Line 193 in 27a949f
I may look into making a PR for that if it's easy to pull off. |
@cromefire see the discussion in #2336 (which also includes a potential solution to the Just FYI, Jib has a general-purpose filtering extension (Maven / Gradle) that you can use to remove arbitrary files or move into other layers. |
Well I'm using gradle in this instance, which has a different system, so maven profiles won't help here. If anything, configurations seem to be a similar thing to maven profiles in the use case. I think you may be confusing gradle and maven here, as there are no profiles in gradle.
Well they are properly set up in a configuration so they can be properly excluded, there's just the lack of an option to tell the plugin to use the proper "non-dev" configuration
While this would probably technically be working, it would be a PITA to filter the files your self, if there's just an easy fix for it. |
Sorry, I did mean to say Gradle instead of Maven. There's no difference between Gradle and Maven in this regard. (In #2336, you'll see that we have the Spring Boot extensions for both Maven and Gradle.) There are multiple ways to have a profile-like behavior in Gradle. Perhaps an easy way is to use Gradle properties. if (project.hasProperty('dev')) {
I agree using profiles is a much simpler way. I guess using a filter extension anyways requires you do use profiles. (BTW, just in case, the filtering extension is a different extension than the Spring Boot extension mentioned in #2336.) |
Actually @loosebazooka has more expertise in dependency configuration in Gradle and will have some opinions about setting up conditional dependencies in Gradle. |
Okay I've missed that one, that seems to work for spring
I don't see a point in point in duplicating things that are already in place here.
Which seems to pretty much what you'd want in this case and also allows you to be more flexible than with properties |
I didn't really find the correct place where the dependencies are being resolved (yet, there's a lot of places where the project configurations and dependencies are mentioned), so sadly I wasn't able to get it working, so if somebody has a clue where that's happening, I can probably make it work |
Well gradle holds two different references to the runtime classpath. One as a Configuration and one as a property on a SourceSet. We use both of these to determine how to arrange the final artifact. You're going to have to modify both of those somehow in The problem with this approach is that if you consider the gradle Even configuring custom Jars seems to requires some sort of manipulation of the underlying CopySpec. It would be helpful to show an example of how another packager handles this? And and example of how you think the configuration should be surfaced. |
Sure I can probably dig something up there but it'll probably take |
What we really need is an example of someone achieving this via another packager, like an example using Jar (which probably uses the underlying archive/copyspec constructs) or an example using Application plugin. For instance, how would you fill this out?
I imagine for any packager to get this done correctly, either
|
So some samples I came across are the license plugin: hierynomus/license-gradle-plugin#184 |
I guess what I'm asking for is an example of how you've set up your Jib can potentially accommodate to a point, but without a user correctly configuring things, we don't want to be a position of debugging someone's gradle build. |
So basically I just have spring boot, where there is the extension, but that one only filters the dev tools and not all |
We are still waiting on someone to provide us with a concrete example (#1778 (comment)), as the team doesn't have a lot of Gradle expertise. |
Here's a quick demo: https://gitlab.com/cromefire_/jib-exclude-demo
You can Inspect the dependencies (in a specific configuration) via In this spring boot app specifically the are 2 configurations of interest:
Here's a scan so you can see it right in your browser: https://scans.gradle.com/s/zrexr57liwk2s/dependencies?toggled=W1swXSxbMCwxMDldLFswLDEwOF1d |
Here's also a similar case of a different plugin that also needed to implement configurable configurations because android (I know that doesn't apply here, but it's a similar case) uses a different configuration: hierynomus/license-gradle-plugin#42 |
The |
I'd also say it's more a bug than a improvement, because this makes it impossible to use for some projects because there's simply no workaround available that I know or can think of. |
Thanks for the info. But it looks like the questions that @loosebazooka asked were rather more around the
Anyways, reading your old comments and the example you just provided, I think your issue is specifically about Spring Boot and the custom |
Well spring boot is just a user of this and I think this is also where @loosebazooka is coming at you can do stuff like this: configurations {
register("docker") {
extendsFrom(productionRuntimeClasspath.get())
}
}
dependencies {
"docker"("org.apache.commons:commons-lang3:3.11")
} Which allows you to easily customize things. |
As of the sourceSets: I have no idea, how to do that, it's probably useful in some cases but those are probably really rare |
So I created a PR, which basically solves the problem with the configurations (see the sample project) |
From your example, I'm not convinced #3034 is the best solution, it's a little too convoluted. I, however, can see the reason that someone would want this. Perhaps we just create a new jib configuration? So users can do something like dependencies {
jib "my.container-only:dependency:1.2.3"
} and if a user wants to take advantage of the |
Well your snippet is completely working with the PR you just have to create the |
So basically: jib {
configurationName.set("jib")
}
configurations {
register("jib")
} (Syntax might differ for the groovy version, I haven't checked that yet but it should work well because of the properties) |
Right, just forcing a convention here though. |
The problem with your |
Well if you want a configuration you need to create a configuration, right? The only difference here is you explicitly opt in as opposed to something that the user might not want is happening in the background. |
It's basically saving 4 lines of code with your proposal while loosing all flexibility. |
So the idea wasn't to extend runtimeClasspath explicitly but instead add extra classpath options to the build.
I'll take a look at the PR. |
I would imagine spring is not the only one doing this. But I've not looked at a lot of frameworks |
@remmeier @dmurat @saturnism @fhoeben @bric3 @atbentley @AndrewBentley6886 @ghilainm @cromefire We've released Jib plugins 3.0 where you can set a custom Gradle Configuration. Check out the usage. @cromefire thanks for your awesome contribution! Indeed, it was a highly requested feature. |
Fixed by #1776. |
@chanseokoh Thanks ! |
The Jib Gradle plugin is hard-coded to make use of the "main" classpath and "runtime" configuration. It should be possible to specify those two values in the JibExtension to allow customizations:
Many/most other Gradle plugins allow to do the same thing to maintain flexiblity of what gets touched by plugin. And effort for allowing that is minimal.
The ticket is related to #894, but as requested created a ticket on its own. In most cases the changes requested here should be simpler and suffice for developers to allow doing customizations. The other ticket then would allow even more customization at expensve of additional complexity.
The text was updated successfully, but these errors were encountered: