-
Notifications
You must be signed in to change notification settings - Fork 274
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
Use new public API to create SourceDirectorySet available since Gradle 5.0 #292
Conversation
String name = sourceSet.name | ||
if (Utils.compareGradleVersion(project, "5.0") < 0) { | ||
// TODO(zhangkun83): remove dependency on Gradle internal APIs once we drop support for < 5.0 | ||
sourceSet.extensions.create('proto', ProtobufSourceDirectorySet, sourceSet.name, fileResolver) |
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.
Why do we need to use ProtobufSourceDirectorySet instead of DefaultSourceDirectorySet? It seems like using DefaultSourceDirectorySet here would make the else more clear. Backward compatibility?
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.
If we used DefaultSourceDirectorySet here, we would have to configure()
it after it's created. Unfortunately, the only configure()
available on Gradle 3.0 is
<T> void configure(Class<T> type,
Action<? super T> action)
That means a custom type would still be necessary.
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.
Oh, because we are passing a Class, not an instance.
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.
Wait ... I don't actually need configure()
to configure it, since I already have the reference to the SDS.
TODO: ProtobufConfiguratorExts.kt is broken.
@marcoferrer, I deleted ProtobufSourceDirectorySet in my latest commit, but that broke ProtobufConfiguratorExts.kt . Could you suggest how to fix it? |
@zhangkun83, I think this should take care of it fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) {
(this as? ExtensionAware)
?.extensions
?.getByName("proto")
?.let { it as? SourceDirectorySet } // <-- We need to cast the result of getByName
?.apply(action)
} |
Awesome. Thank you @marcoferrer! |
"generate-proto-" + name, this.fileResolver, new DefaultDirectoryFileTreeFactory()) | ||
String srcSetName = "generate-proto-" + name | ||
SourceDirectorySet srcSet | ||
if (Utils.compareGradleVersion(project, "5.0") < 0) { |
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.
Why did you use a 5.0
?
Resolves #280