Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express compile classpath as a FileCollection, propagating dependencies #31

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions plugin/src/main/kotlin/me/tylerbwong/gradle/metalava/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.tylerbwong.gradle.metalava
import com.android.build.gradle.LibraryExtension
import me.tylerbwong.gradle.metalava.extension.MetalavaExtension
import org.gradle.api.Project
import org.gradle.api.file.FileCollection
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.findByType
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
Expand All @@ -11,23 +12,24 @@ import java.io.File
internal sealed class Module {

open val bootClasspath: Collection<File> = emptyList()
abstract val compileClasspath: Collection<File>
abstract val compileClasspath: FileCollection

class Android(private val extension: LibraryExtension, private val variantName: String) : Module() {
override val bootClasspath: Collection<File>
get() = extension.bootClasspath
override val compileClasspath: Collection<File>
override val compileClasspath: FileCollection
get() = extension.libraryVariants.find {
it.name.contains(variantName, ignoreCase = true)
}?.getCompileClasspath(null)?.filter { it.exists() }?.files ?: emptyList()
}?.getCompileClasspath(null)?.filter { it.exists() }!!
}

class Multiplatform(private val extension: KotlinMultiplatformExtension) : Module() {
override val compileClasspath: Collection<File>
override val compileClasspath: FileCollection
get() = extension.targets
.flatMap { it.compilations }
.filter { it.defaultSourceSetName.contains("main", ignoreCase = true) }
.flatMap { it.compileDependencyFiles }
.map { it.compileDependencyFiles }
.reduce(FileCollection::plus)
.filter { it.exists() && it.checkDirectory(listOf(".jar", ".class")) }
}

Expand All @@ -36,10 +38,11 @@ internal sealed class Module {
get() = File(System.getProperty("java.home")).walkTopDown()
.toList()
.filter { it.exists() && it.name == "rt.jar" }
override val compileClasspath: Collection<File>
override val compileClasspath: FileCollection
get() = extension.sourceSets
.filter { it.name.contains("main", ignoreCase = true) }
.flatMap { it.compileClasspath }
.map { it.compileClasspath }
.reduce(FileCollection::plus)
.filter { it.exists() && it.checkDirectory(listOf(".jar", ".class")) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ internal object MetalavaSignature : MetalavaTaskContainer() {
.toList()
}

inputs.files(module.compileClasspath)
inputs.files(sourceFiles)
inputs.property("documentation", extension.documentation)
inputs.property("format", extension.format)
Expand All @@ -56,7 +57,7 @@ internal object MetalavaSignature : MetalavaTaskContainer() {
outputs.file(filename)

doFirst {
val fullClasspath = (module.bootClasspath + module.compileClasspath).joinToString(File.pathSeparator)
val fullClasspath = (module.bootClasspath + module.compileClasspath.files).joinToString(File.pathSeparator)

val sourcePaths = listOf("--source-path") + sourceFiles.joinToString(File.pathSeparator)

Expand Down