-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Configurable gradle configurations #3034
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
Configurable gradle configurations #3034
Conversation
This comment has been minimized.
This comment has been minimized.
In practice this looks like: jib {
configurationName.set("docker")
} |
@googlebot I signed it! |
This is basically working, but I'm not (yet) enough into the mocking stuff to get the tests fixed up again |
Okay got all of them fixed. |
Thanks for the PR! I think overall this looks good but haven't looked into all the details or done tests. This week we're focused on another high priority work, so please be patient. |
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java
Outdated
Show resolved
Hide resolved
Should we also update jib/jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java Lines 211 to 217 in 532a86b
|
Yes, I think so, will have a look |
@Input | ||
@Optional | ||
public Property<String> getConfigurationName() { | ||
return configurationName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
our of curiosity, can we just set the property to the system property value here?
public Property<String> getConfigurationName() {
String property = System.getProperty(PropertyNames.CONFIGURATION_NAME);
if (property != null) {
configurationName.set(property);
}
return configurationName;
}
while this still looks a little odd, if it is possible, it matches more closely our previous patterns and it removes the ambiguous GetconfigurationName/readConfigurationName
situation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've realized it via a default value now, that sounds like a good idea anyway because it gives the user all the control. So if you want the override behavior you can just set the value to System.getProperty("some.property", "default")
. The downside is of course that this is different from the rest of the API, creating an inconsistency in some cases.
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #3034 +/- ##
============================================
- Coverage 71.18% 71.09% -0.09%
+ Complexity 2314 2313 -1
============================================
Files 278 278
Lines 9761 9784 +23
Branches 990 991 +1
============================================
+ Hits 6948 6956 +8
- Misses 2471 2483 +12
- Partials 342 345 +3
Continue to review full report at Codecov.
|
That breaks the build (seems to exclude the own code) and it works without it, so I guess not (I just added it, instead of replacing it, that should do the job). |
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/GradleProjectProperties.java
Outdated
Show resolved
Hide resolved
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibExtension.java
Outdated
Show resolved
Hide resolved
jib-gradle-plugin/src/main/java/com/google/cloud/tools/jib/gradle/JibPlugin.java
Show resolved
Hide resolved
…dle/JibExtension.java Co-authored-by: Chanseok Oh <[email protected]>
…le-configurations
# Conflicts: # jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java
Not sure what's up with the code coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for your contribution! I think we can merge this when ready.
Will also submit a quick followup (after merge), to get the gradle version up to date, it's basically a 2 line change now with the new testing |
Merging now. Thanks again for your contribution! @mpeddada1 we need to add the config param to the plugin doc and also update CHANGELOG. |
@cromefire I was trying to test the way we support this by creating a small Gradle sample (the following code). public class SimpleTask extends DefaultTask {
private final Property<String> contents;
@Inject
public SimpleTask(ObjectFactory objects) {
contents = objects.property(String.class).convention("default");
}
@Input
public Property<String> getContents() {
String property = System.getProperty("simpleTask.contents");
if (property != null) {
contents.set(property);
}
return contents;
}
@OutputFile
public File getOutputFile() {
return getProject().getBuildDir().toPath().resolve("simpleTask.out").toFile();
}
@TaskAction
public void doWork() {
... calls getContents() ...
} It fails with an error when I provide the system property
I wasn't able to reproduce this in Jib, but I'm concerned that the way we implemented this has the potential to fail if conditions are met. Your thoughts? |
Maybe it's because of your usage of |
I think
The error is due to calling |
Maybe one should check for |
All in all it is a work around and not really how it was intended to be used so yeah that's the tradeoff... |
Oh, that did the trick! I now see it was applying the system property multiple times. Thanks! I should update the code. |
@Optional | ||
public Property<String> getConfigurationName() { | ||
String property = System.getProperty(PropertyNames.CONFIGURATION_NAME); | ||
if (property != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FTR, this can be problematic and should be fixed. #3034 (comment)
Fixes parts of #1778
This introduces a new configuration option
configurationName
that just sets the name of the gradle configuration that should be used.