This message was deleted.
# community-support
s
This message was deleted.
t
is it possible to achieve the same with a pure java project? can i define a constant in my groovy gradle file that i can import into my kotlin code?
e
v
Or simply a task of type
WriteProperties
that produces a properties file you can then load from your code. Or a
.properties
or whatever file with placeholders in your resources where you fill in the placeholders by configuring the
processResources
task. As @ephemient said, many, many ways.
👍 1
t
thanks 😄 i am property file "Averse" !!!
v
Then generate a YAML file or JSON file or whatever you like, doesn't matter.
The principle is the same. Either have a task that generates it, or have a version with placeholders in the resources that you then replace
e
generating source code for primitives isn't hard either, just have to take some care with strings
v
While I personally would not generate code if not really necessary, especially if it is the only generated thing. Because you then always have the problem that a fresh checkout, or a web view does not have the generated code, which typically is more disturbing than a missing resource file. But yes, generating code would also be possible.
t
i do lile the YAML idea, i have successfully employed it in other projects im not sure why i like YAML and not property files though 🤔 especialy this "`com.github.bmoliveirasnake yamlv1.18-android`"
e
Android unfortunately makes Java resources rather terrible: https://github.com/FasterXML/jackson-core/pull/49 so on that platform, it is far better to use native Android res or code generation than to generate a properties or YAML file in resources
v
Well, he asked about non-Android project
e
that's true. although if you are using targeting Kotlin Multiplatform, there's no Java resources on native or JS either
v
Ok, let me rephrase and quote. He specifically asked "is it possible to achieve the same *with a pure java project*y?" 🙂
e
"pure java" and "kotlin" in the same message, so I assumed from the start that they were not consistent in what they are asking for
t
as i am not familiar with kotlin gradle dsl I used "pure java" in an attempt to obtain a groovy gradle solution and to signify this is not an Android project i am in fact creating a kotlin code generator application using kotlinpoet, and not an annotation processor, gradle plugin, or android app. the groovy gradle solution to my issue would not be affected by the language i am developing in(?)🤔
v
I would always use Kotlin DSL actually, as you get type-safe build scripts, better error messages, and muuuch better IDE support. And yes, the language you use in your build scripts is absolutely independent from the language you use in your production code. But using "pure java" as synonym for "Groovy DSL" is actually pretty strange, as Groovy is not Java and it more sound to me like you talked about your production code, especially as you cannot write a build script in Java. 😄
d
Why wouldn't you use the merge strategy and define the constant along src/{flavor}/java?
v
Who is "you"? And what do you mean?
d
You would’ve been the original poster. Not sure why but the second post didn’t show on my phone but did now. My post is moot. For a pure Gradle project with no AGP, you’d have to go the route suggested for a YAML file. You could do something else, but our team has had a strong opposition to generating things in build scripts using build scripts (as in the original snippet) but rather based on using AGP’s merge strategy.