I'm trying to port this to kotlin and merge it wit...
# gradle
b
I'm trying to port this to kotlin and merge it with my buildscript for last 3-4 hours and I'm completely stuck... https://github.com/PaleoCrafter/Dependency-Extraction-Example/blob/coremod-separation/build.gradle
I tried exactly that syntax, and the ForgeGradle plugin game me that error. I also tried:
Copy code
tasks {
    "coreJar"(Jar::class) {
          // logic here
    }
}
with the same result
j
What error?
b
Copy code
* What went wrong:
A problem occurred configuring root project '1.12'.
> coreJar  is not a jar task. Can only reobf jars!
this is part of ForgeGradle trying to tell me something
j
Can you link to your current code?
b
it comes from the equivalent of this:
Copy code
reobf {
    coreJar { mappingType = 'SEARGE' }
}
which is
Copy code
configure<NamedDomainObjectContainer<ReobfTaskFactory.ReobfTaskWrapper>> {
    create("coreJar").apply {
        mappingType = ReobfMappingType.SEARGE
    }
}
my current code: https://hastebin.com/sicemaruna.scala (this is with addition to my project)
j
You're sure that:
Copy code
configure<NamedDomainObjectContainer<ReobfTaskFactory.ReobfTaskWrapper>>
is equivalent??
b
yes, I'm sure
j
So in full, you have something like this?
Copy code
task coreJar(type: Jar) {
    //...
}

configure<NamedDomainObjectContainer<ReobfTaskFactory.ReobfTaskWrapper>> {
    create("coreJar").apply {
        mappingType = ReobfMappingType.SEARGE
    }
}
b
well, I have
Copy code
tasks {
    "coreJar"(Jar::class) {
          // logic here
    }
}
which I saw in samples
but basically, yes
j
Try putting:
Copy code
configure<NamedDomainObjectContainer<ReobfTaskFactory.ReobfTaskWrapper>> {
    create("coreJar").apply {
        mappingType = ReobfMappingType.SEARGE
    }
}
Into an
afterEvaluate
block and see what happens
b
well, I actually have 2 of create("something").apply { blocks, I just realized that it could be bug in that plugin that makes it break when 2+ are there
it seems to work with afterEvaluate
but Ihave no idea why it's needed when it works without kotlin dsl
j
I agree that it's strange. I'm going to guess that there's an execution ordering problem.
b
Considering the strange things the FG plugin does, it's not that unlikely
well, now I actually get this
Copy code
* What went wrong:
Execution failed for task ':reobfCoreJar'.
> org.gradle.jvm.tasks.Jar_Decorated cannot be cast to org.gradle.api.tasks.bundling.Jar
and the previous error is straneg too because that part that does
throw new GradleConfigurationException(jarName + "  is not a jar task. Can only reobf jars!");
is in afterEvaluate in that plugin's code
j
So, Gradle weirdness, there are actually two
Jar
tasks. One is just an interface for the other one.
b
is it just a change in gradle internals in some version that broke the plugin?
OH
default imports broke it
j
Yea, that.
Because the default
Jar
is probably different than the one the plugin expects.
b
Should I report it as an issue that the
org.gradle.api.tasks.bundling.Jar
needs fully qualified name to be used?
it's impossible to use without using fully qualified name
j
Yea, I think the forge gradle plugin needs to be updated.
b
to use the other jar task?
j
Yea,
b
Good luck with getting ANY change into ForgeGradle...
also to me it looks like
org.gradle.api.tasks.bundling.Jar
is actually in the API. Shouldn't that one be actually imported by default?
j
@bamboo or @eskatos Can you explain the weird
Jar
api, why there are two of them, ect... to me again because I still don't really understand. I know it has something to do with not breaking the API.
b
and yet it turned out to be a breaking change
j
True, it probably changed during a major version bump. ¯\_(ツ)_/¯
b
wekk, breaking change when used together with kotlin's default imports
j
I mean, these are the same default imports used by Groovy too.
b
I would be able to debug it if I could add breakpoints in gradle code...
j
Supposedly you can, but I haven't ever been able to get it to work.
b
You can add them but they don't work
It's also unlikely it can be fixed in FG because it probably still builds against gradle 2.x
j
Well that's their problem. That's really old, they should update their build.
b
its not their problem if they don't claim compatibility with gradle 4.x
j
¯\_(ツ)_/¯
b
anyway, now I can try to make publishing to maven work
e
Like Jonathan said, Kotlin DSL default imports are the very same as the ones you get in the Groovy DSL. But thanks to the Groovy magic it may work anyway, but Kotlin doing strict type checking forces you to use a fqcn here. Agreed that FG should update their build, or you have to live with the fqcn.
After taking a closer look, that’s on Gradle & Kotlin DSL. The Groovy DSL actually imports the “old”
Jar
task by default. This will be fixed in the upcoming Gradle 4.3.