I don't know why I keep on getting mysterious erro...
# gradle
d
I don't know why I keep on getting mysterious errors in gradle like this:
Copy code
e: .../app/build.gradle.kts:10:45: Unresolved reference: util
e: .../app/build.gradle.kts:11:65: Unresolved reference: newDataInputStream
I updated to gradle 7.3.3 and android plugin 7.0.4...
It's for these two lines:
Copy code
val localProps: java.util.Properties = java.util.Properties()
localProps.load(project.rootProject.file("my-local.properties").newDataInputStream())
v
If you have the
java-base
plugin (or one that applies it) applied, then
java
is an extension. The
java
extension wins over the
java
package. You instead need to import the class you want to use as there it is unambiguous that you want the package, not the extension.
The
java
extension does not have a
util
property which is what the error is telling you
d
🤕... Thanks for the explanation! They really should have given that another name... or at least AndroidStudio should be a bit smarter!
v
Yes, AS and IJ should be a bit smarter about that, report it to JetBrains so it can get fixed. But another name is not really necessary, because what you do is non-idiomatic. 🙂
In an idiomatic build, build scripts itself should not contain logic, but be as declarative as possible. Custom logic should be done in custom plugins and custom tasks, and then you don't have that problem. 🙂 And naming the extension
java
is just natural.
Besides that, when the naming was done, no Kotlin DSL existed and in the Groovy DSL it does not lead to a problem.
d
Yeah, true... but in this case, a whole plugin for those two lines? It's basically to not have to commit the release keys to Git...
v
Well, almost no build is fully idiomatic, just speaking about a perfect world. 🙂
And you just have to add the import and all is well and better readable anyway.
I also don't know why IJ adds FQCNs anyway instead of using imports.
d
Yeah, I was wondering about that too 🤔...