mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Dependencies for variants.
Fixes https://github.com/cbeust/kobalt/issues/204
This commit is contained in:
parent
24229a8714
commit
7ef80787dd
7 changed files with 88 additions and 48 deletions
|
@ -99,7 +99,11 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
|||
@Suppress("UNCHECKED_CAST")
|
||||
val dependentProjects = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS)
|
||||
as List<ProjectDescription>
|
||||
val allDependencies = project.compileDependencies + project.compileRuntimeDependencies
|
||||
val allDependencies = project.compileDependencies + project.compileRuntimeDependencies +
|
||||
context.variant.buildType.compileDependencies +
|
||||
context.variant.buildType.compileRuntimeDependencies +
|
||||
context.variant.productFlavor.compileDependencies +
|
||||
context.variant.productFlavor.compileRuntimeDependencies
|
||||
val transitiveDependencies = dependencyManager.calculateDependencies(project, context, dependentProjects,
|
||||
allDependencies)
|
||||
transitiveDependencies.map {
|
||||
|
|
|
@ -188,7 +188,7 @@ class Variant(val initialProductFlavor: ProductFlavorConfig? = null,
|
|||
override fun toString() = toTask("")
|
||||
|
||||
companion object {
|
||||
val DEFAULT_PRODUCT_FLAVOR = ProductFlavorConfig("")
|
||||
val DEFAULT_PRODUCT_FLAVOR = ProductFlavorConfig(null, "")
|
||||
val DEFAULT_BUILD_TYPE = BuildTypeConfig(null, "")
|
||||
|
||||
fun allVariants(project: Project): List<Variant> {
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
|
||||
class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig,
|
||||
IDependencyHolder by DependencyHolder(project) {
|
||||
var minifyEnabled = false
|
||||
var applicationIdSuffix: String? = null
|
||||
var proguardFile: String? = null
|
||||
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(this, name).apply {
|
||||
init()
|
||||
addBuildType(name, this)
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Various elements in a build file let you specify dependencies: projects, buildType and productFlavor.
|
||||
* They all implement this interface and delegate to an instance of the concrete class below.
|
||||
*/
|
||||
interface IDependencyHolder {
|
||||
val compileDependencies : ArrayList<IClasspathDependency>
|
||||
val compileProvidedDependencies : ArrayList<IClasspathDependency>
|
||||
val compileRuntimeDependencies : ArrayList<IClasspathDependency>
|
||||
val excludedDependencies : ArrayList<IClasspathDependency>
|
||||
|
||||
@Directive
|
||||
var dependencies: Dependencies?
|
||||
|
||||
@Directive
|
||||
fun dependencies(init: Dependencies.() -> Unit) : Dependencies
|
||||
}
|
||||
|
||||
open class DependencyHolder(val project: Project?) : IDependencyHolder {
|
||||
override val compileDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
override val excludedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
|
||||
override var dependencies : Dependencies? = null
|
||||
|
||||
override fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(project!!, compileDependencies, compileProvidedDependencies,
|
||||
compileRuntimeDependencies, excludedDependencies)
|
||||
dependencies!!.init()
|
||||
return dependencies!!
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package com.beust.kobalt.api
|
||||
|
||||
import com.beust.kobalt.api.annotation.Directive
|
||||
|
||||
class ProductFlavorConfig(val project: Project?, val name: String) : IBuildConfig,
|
||||
IDependencyHolder by DependencyHolder(project) {
|
||||
var applicationId: String? = null
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(this, name).apply {
|
||||
init()
|
||||
addProductFlavor(name, this)
|
||||
}
|
||||
|
||||
|
|
@ -18,12 +18,12 @@ open class Project(
|
|||
@Directive open var group: String? = null,
|
||||
@Directive open var artifactId: String? = null,
|
||||
@Directive open var packaging: String? = null,
|
||||
@Directive open var dependencies: Dependencies? = null,
|
||||
@Directive open var description : String = "",
|
||||
@Directive open var scm : Scm? = null,
|
||||
@Directive open var url: String? = null,
|
||||
@Directive open var licenses: List<License> = arrayListOf<License>(),
|
||||
@Directive open var packageName: String? = group) : IBuildConfig {
|
||||
@Directive open var packageName: String? = group)
|
||||
: IBuildConfig, IDependencyHolder by DependencyHolder(null) {
|
||||
|
||||
class ProjectExtra(project: Project) {
|
||||
val dependsOn = arrayListOf<Project>()
|
||||
|
@ -83,19 +83,6 @@ open class Project(
|
|||
// Dependencies
|
||||
//
|
||||
|
||||
@Directive
|
||||
fun dependencies(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(this, compileDependencies, compileProvidedDependencies,
|
||||
compileRuntimeDependencies, excludedDependencies)
|
||||
dependencies!!.init()
|
||||
return dependencies!!
|
||||
}
|
||||
|
||||
val compileDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
val compileProvidedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
val compileRuntimeDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
val excludedDependencies : ArrayList<IClasspathDependency> = arrayListOf()
|
||||
|
||||
@Directive
|
||||
fun dependenciesTest(init: Dependencies.() -> Unit) : Dependencies {
|
||||
dependencies = Dependencies(this, testDependencies, testProvidedDependencies, compileRuntimeDependencies,
|
||||
|
@ -208,36 +195,6 @@ interface IBuildConfig {
|
|||
}
|
||||
}
|
||||
|
||||
class ProductFlavorConfig(val name: String) : IBuildConfig {
|
||||
var applicationId: String? = null
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.productFlavor(name: String, init: ProductFlavorConfig.() -> Unit) = ProductFlavorConfig(name).apply {
|
||||
init()
|
||||
addProductFlavor(name, this)
|
||||
}
|
||||
|
||||
class BuildTypeConfig(val project: Project?, val name: String) : IBuildConfig {
|
||||
var minifyEnabled = false
|
||||
var applicationIdSuffix: String? = null
|
||||
var proguardFile: String? = null
|
||||
|
||||
// fun getDefaultProguardFile(name: String) : String {
|
||||
// val androidPlugin = Plugins.findPlugin(AndroidPlugin.PLUGIN_NAME) as AndroidPlugin
|
||||
// return Proguard(androidPlugin.androidHome(project)).getDefaultProguardFile(name)
|
||||
// }
|
||||
|
||||
override var buildConfig : BuildConfig? = BuildConfig()
|
||||
}
|
||||
|
||||
@Directive
|
||||
fun Project.buildType(name: String, init: BuildTypeConfig.() -> Unit) = BuildTypeConfig(this, name).apply {
|
||||
init()
|
||||
addBuildType(name, this)
|
||||
}
|
||||
|
||||
fun Project.defaultConfig(init: BuildConfig.() -> Unit) = let { project ->
|
||||
BuildConfig().apply {
|
||||
init()
|
||||
|
|
|
@ -191,7 +191,12 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
|
|||
val transitive = hashSetOf<IClasspathDependency>()
|
||||
val projects = listOf(ProjectDescription(project, project.projectExtra.dependsOn))
|
||||
with(project) {
|
||||
val deps = arrayListOf(compileDependencies, compileProvidedDependencies)
|
||||
val deps = arrayListOf(compileDependencies, compileProvidedDependencies,
|
||||
context.variant.buildType.compileDependencies,
|
||||
context.variant.buildType.compileProvidedDependencies,
|
||||
context.variant.productFlavor.compileDependencies,
|
||||
context.variant.productFlavor.compileProvidedDependencies
|
||||
)
|
||||
if (isTest) {
|
||||
deps.add(testDependencies)
|
||||
deps.add(testProvidedDependencies)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue