Hm... I see that <https://github.com/gradle/kotlin...
# gradle
c
Hm... I see that https://github.com/gradle/kotlin-dsl/issues/337 is closed but
api
in
Copy code
dependencies {
    api(...)
}
is still not being resolved, strange because
implementation(...)
is and works.
gradle: 4.3.1 kotlin-gradle-plugin: 1.1.60
e
What plugins were applied? using the
plugins {}
block? Does that configuration exist in your build? What happen if you use
"api"(..)
instead?
Just read the backlog a bit and found some build script of yours. Note that the Kotlin plugin apply the
java
plugin but not the
java-library
plugin. So the
api
configuration does not exist, that’s why it’s accessor is not available.
c
@eskatos those are irrelevant for this post. Setup is like this: parent project (build.gradle) has plugins block with
id 'java-library'
, child project (build.gradle.kts) looks like this:
Copy code
apply<JavaLibraryPlugin>()
apply { plugin("org.jetbrains.kotlin.jvm") }

dependencies {
	api(..)
}
At the moment I've added
fun DependencyHandler.api(dependencyNotation: Any): Dependency = add("api", dependencyNotation)
and it works, it also works with
"api"
, but I try to avoid that syntax whenever possible.
By the way, is
apply<KotlinPlatformJvmPlugin>()
the equivalent of
apply { plugin("org.jetbrains.kotlin.jvm") }
or are these different plugins?
e
You won’t get static configuration accessors if you use
apply { plugin(..) }
, that’s expected. You should use the
plugins {}
block in your child projects too.
you can do this in your parent project:
Copy code
plugins {
  id("something") version "1.0" apply false
}
and then in your child projects:
Copy code
plugins {
  id("something")
}
if you want to keep the version declaration in one place
this does not apply to
java-library
as it is a core plugin, but it does to
org.jetbrains.kotlin.jvm
c
It complains about
org.jetbrains.kotlin.jvm
already being on classpath.
Copy code
Plugin 'org.jetbrains.kotlin.jvm' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add "apply plugin: 'org.jetbrains.kotlin.jvm'" to the body of the script to use the plugin.
e
c
I have gradle 4.3.1, should've worked then.
e
It should yes. Something else must be going on. Any chance you could share your build or a reproducer?
c
Ooops, my bad, gradle was indeed switched to 4.0.1, probably testing something previously.
But as soon as I've switched to 4.3.1 other stuff broke, I'll formulate a question in a couple of minutes.
e
Ah, cool, this makes more sense!
Sure thing
c
So, I've changed my `apply`s to plugins block:
Copy code
plugins {
	id("java-library")
	id("org.jetbrains.kotlin.jvm")
}
api
is still not resolved, plus stdlib functions can't be resolved now. I had this working in 4.0.1 with
apply
, now it doesn't (checkNotNull not resolved):
Copy code
val lib: Map<String, Any> by extra
fun lib(key: String) = checkNotNull(lib[key]) {
	"Could not find dependency \"lib.$key\". Did you forget to add it to libraries.gradle?"
}
Remembering yesterday's problem, stopped all gradle daemons and restarted IntelliJ, everything works now.
@eskatos Greatly appreciate your time, thank you!
e
Thanks! Great you sorted it out!