How can I convert this to kotlin dsl? ```include '...
# gradle
j
How can I convert this to kotlin dsl?
Copy code
include ':library'
project(':library').projectDir = new File(settingsDir, '../MyLibrary/library')
I don’t find any info on how to set the project path with kotlin
o
Copy code
include(":library")
project(":library").projectDir = File(settingsDir, "../MyLibrary/library")
?
j
.projectDir
isn’t available 😕
o
that's pretty odd
j
actually, I just found that now
Copy code
project(":inorder-common").dependencyProject.projectDir = File("")
I’ll try and see if it works
o
both the setter and getter are the same type, so kotlin should generate a dynamic property....
you could try explicitly doing
.setProjectDir(...)
what is
dependencyProject
? I don't see that field at all
j
it’s a method from
public interface ProjectDependency
o
right, but that's not what you should have there
you're in a
settings.gradle.kts
, right?
j
well,
project()
returns that type
Copy code
fun DependencyHandler.project(
    path: String,
    configuration: String? = null
): ProjectDependency
so I guess that’s normal?
o
you've got the wrong
project
then
it's not on DependencyHandler, it's on the implicit
Settings
object of the build script
j
so I added
Copy code
project(":inorder-common").projectDir = File("../inorder-common")
in my
buildscript
block, which allows me to access the property but I get this error
val cannot be reassigned
o
I don't think that works in buildscript, it only works in
settings.gradle.kts
in
buildscript
you're just getting a normal configuration-time
Project
instance, which cannot have the project directory re-assigned
j
ok, I got confused when you talked about buildcript earlier. And I didn’t know the scripts were acting like scope over there content, so one can access different stuff in
settings.gradle.kts
compare to
build.gradle.kts
good to know. Thanks for the help! I’m running in other issues but now but the projects are linked now 🙂
o
yes, there are multiple "phases" of sorts, there's a "settings" phase where you can change the project name and directory, the scope of this is `settings.gradle.kts`; a "configuration" phase where you setup task definitions and wire dependencies, anything outside of a task action, the scope of this is most of any
build.gradle.kts
or the
apply
of a plugin to a `Project`; and finally an "execution" phase where the actions of the tasks are executed.
to clarify configuration and execution:
Copy code
tasks.register("yourTask") {
  inputs.file("someFile.txt") // this is configuration phase
  doLast {
    // this is in the execution phase because of `doLast`, another alternative is `doFirst`, or in a task class `@TaskAction`
    print(file("someFile.txt").absolutePath)
  }
}
j
I’m actually running in one more issue now. The common module adds a jvm target for my backend, a jvm target for android, and an ios target. I managed to add the dependency to my backend project with previous help but when I run the gradle build command it fails due to conflicting jvm variants. I see in the doc I should create attributes here but I don’t see how to specify anything in my backend project
o
hmm, are you sure that the jvm variants are conflicting? that would indicate that you've declared the wrong source/target compatibilities for one of the projects I think
j
I have a
jvm("backend")
and
jvm("android")
, I did not manage to import the correct target with the local setup so I ended up publishing them to a maven repo with separate attributes, which I can import from my later through gradle,without custom settings in each clients. All in all it works well now 🙂
254 Views