Skip to content

Commit

Permalink
Express compile classpath as a FileCollection, propagating dependenci…
Browse files Browse the repository at this point in the history
…es (#31)
  • Loading branch information
DSteve595 authored Feb 18, 2022
1 parent 9bb19dc commit d0420dd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
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

0 comments on commit d0420dd

Please sign in to comment.