…but somehow, `from(compileJava)` is not working. ...
# gradle
x
…but somehow,
from(compileJava)
is not working. Any advice?
c
Copy code
task<Zip>("distribution") {
    dependsOn("jar")

    archiveFileName.set("${project.name}.zip")
    from(tasks.compileJava)
    from(tasks.processResources)
    into("lib") {
        from(configurations.runtimeClasspath)
    }
}
x
It looks like it doesn’t understand `tasks.compileJava`:
Copy code
* What went wrong:
Script compilation error:

  Line 159:     from(tasks.compileJava)
                           ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
                               public val TaskContainer.compileJava: TaskProvider<JavaCompile> defined in org.gradle.kotlin.dsl

1 error
c
which version of gradle are you using?
x
What I don’t fully understand is why
from(processResources)
works fine…
I’m using `5.4.1`…and it’s a Java project (not Kotlin)
c
worked for me in 5.2.1, I'll try 5.4.1, just a sec
works in 5.4.1, too. Strange that it does not work for you.
when you ctrl click
from
does it bring up
org.gradle.api.tasks.AbstractCopyTask
?
x
Yeah…
The reason I didn’t need
tasks.
is because
task<Zip>("distribution")
itself is inside the
tasks
block…
c
ah. ok.
what about lazy method:
Copy code
tasks {
    register<Zip>("distribution") {
        dependsOn("jar")

        archiveFileName.set("${project.name}.zip")
        from(compileJava)
        from(processResources)
        into("lib") {
            from(configurations.runtimeClasspath)
        }
    }
}
x
I tried that one also…
c
Something weird is going on here, both versions work in my test project. The last one is the best practice as I understand it in terms of tasks configuration.
I'd double check versions of everything first, then go through whole build script to see if something could be interfering, but I fail to imagine what could it be aside from gradle version.
x
Yeah…let me see…thanks for the help! 👏
c
Good Luck!
g
Most probably you don’t have those type-safe accessors because do not use
plugins {}
block with applied java plugin. To use them you have to use:
Copy code
plugins {
  java // or kotlin("jvm")
}
If you use
plugin.apply
it will not work
👆 1
x
I'm using the
java
plugin in the
plugins { }
block, as you stated, slightly different (like:
id("org.gradle.java")
), but it's there...
It looks like
from(compileJava)
doesn't have any effect; it generates the ZIP file, but with no classes, just the first segment of the package declaration(s) as a folder:
com/
g
So it actually available, because above you showed an error that says that this accessor is not available