1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 08:27:12 -07:00

GITHUB-215: Bug in dependent project classpath.

Fixes https://github.com/cbeust/kobalt/issues/215
This commit is contained in:
Cedric Beust 2016-05-30 12:52:42 -07:00
parent 6ac16074f0
commit f89688ae19
6 changed files with 18 additions and 34 deletions

View file

@ -2,10 +2,8 @@ package com.beust.kobalt
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectDescription
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.archive.Jar
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.*
import com.google.inject.Inject
@ -97,15 +95,12 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
val seen = hashSetOf<String>()
@Suppress("UNCHECKED_CAST")
val dependentProjects = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS)
as List<ProjectDescription>
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)
val transitiveDependencies = dependencyManager.calculateDependencies(project, context, allDependencies)
transitiveDependencies.map {
it.jarFile.get()
}.forEach { file : File ->

View file

@ -34,6 +34,5 @@ interface IDependencyManager {
* allDependencies is typically either compileDependencies or testDependencies
*/
fun calculateDependencies(project: Project?, context: KobaltContext,
dependentProjects: List<ProjectDescription> = emptyList(),
vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency>
}

View file

@ -85,14 +85,13 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
* allDependencies is typically either compileDependencies or testDependencies
*/
override fun calculateDependencies(project: Project?, context: KobaltContext,
dependentProjects: List<ProjectDescription>,
vararg allDependencies: List<IClasspathDependency>): List<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>()
allDependencies.forEach { dependencies ->
result.addAll(transitiveClosure(dependencies))
}
result.addAll(runClasspathContributors(project, context))
result.addAll(dependentProjectDependencies(dependentProjects, project, context))
result.addAll(dependentProjectDependencies(project, context))
return result
}
@ -169,27 +168,25 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
* If this project depends on other projects, we need to include their jar file and also
* their own dependencies
*/
private fun dependentProjectDependencies(projectDescriptions: List<ProjectDescription>,
private fun dependentProjectDependencies(
project: Project?, context: KobaltContext) : List<IClasspathDependency> {
val result = arrayListOf<IClasspathDependency>()
projectDescriptions.filter {
it.project.name == project?.name
}.forEach { pd ->
pd.dependsOn.forEach { p ->
if (project == null) {
return emptyList()
} else {
val result = arrayListOf<IClasspathDependency>()
project.projectExtra.dependsOn.forEach { p ->
result.add(FileDependency(KFiles.joinDir(p.directory, p.classesDir(context))))
val otherDependencies = calculateDependencies(p, context, projectDescriptions,
p.compileDependencies)
val otherDependencies = calculateDependencies(p, context, p.compileDependencies)
result.addAll(otherDependencies)
}
}
return result
}
return result
}
}
private fun dependencies(project: Project, context: KobaltContext, isTest: Boolean)
: List<IClasspathDependency> {
val transitive = hashSetOf<IClasspathDependency>()
val projects = listOf(ProjectDescription(project, project.projectExtra.dependsOn))
with(project) {
val deps = arrayListOf(compileDependencies, compileProvidedDependencies,
context.variant.buildType.compileDependencies,
@ -202,7 +199,7 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val
deps.add(testProvidedDependencies)
}
deps.filter { it.any() }.forEach {
transitive.addAll(calculateDependencies(project, context, projects, it))
transitive.addAll(calculateDependencies(project, context, it))
}
}

View file

@ -7,7 +7,6 @@ import com.beust.kobalt.api.annotation.Task
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.archive.Jar
import com.beust.kobalt.internal.ActorUtils
import com.beust.kobalt.internal.JvmCompilerPlugin
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.KobaltExecutors
@ -106,12 +105,10 @@ class ApplicationPlugin @Inject constructor(val configActor: ConfigActor<Applica
val java = JavaInfo.create(File(SystemProperties.javaBase)).javaExecutable!!
if (! isFatJar(packages, jarName)) {
@Suppress("UNCHECKED_CAST")
val projDeps = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS)
as List<ProjectDescription>
// If the jar file is not fat, we need to add the transitive closure of all dependencies
// on the classpath
val allTheDependencies =
dependencyManager.calculateDependencies(project, context, projDeps,
dependencyManager.calculateDependencies(project, context,
allDependencies = project.compileDependencies).map { it.jarFile.get().path }
allDeps.addAll(allTheDependencies)
}

View file

@ -118,8 +118,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val analyzer = Analyzer().apply {
jar = aQute.bnd.osgi.Jar(project.projectProperties.get(Archives.JAR_NAME) as String)
val dependencies = project.compileDependencies + project.compileRuntimeDependencies
val dependentProjects = project.dependentProjects
dependencyManager.calculateDependencies(project, context, dependentProjects, dependencies).forEach {
dependencyManager.calculateDependencies(project, context, dependencies).forEach {
addClasspath(it.jarFile.get())
}
setProperty(Analyzer.BUNDLE_VERSION, project.version)

View file

@ -1,13 +1,12 @@
package com.beust.kobalt.plugin.packaging
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.JarGenerator
import com.beust.kobalt.archive.War
import com.beust.kobalt.api.IClasspathDependency
import com.beust.kobalt.api.KobaltContext
import com.beust.kobalt.api.Project
import com.beust.kobalt.api.ProjectDescription
import com.beust.kobalt.archive.Archives
import com.beust.kobalt.archive.War
import com.beust.kobalt.maven.DependencyManager
import com.beust.kobalt.misc.From
import com.beust.kobalt.misc.IncludedFile
@ -40,9 +39,7 @@ class WarGenerator @Inject constructor(val dependencyManager: DependencyManager)
// The transitive closure of libraries goes into WEB-INF/libs.
// Copy them all in kobaltBuild/war/WEB-INF/libs and create one IncludedFile out of that directory
//
val dependentProjects = listOf(ProjectDescription(project, project.projectExtra.dependsOn))
val allDependencies = dependencyManager.calculateDependencies(project, context, dependentProjects,
project.compileDependencies)
val allDependencies = dependencyManager.calculateDependencies(project, context, project.compileDependencies)
val outDir = project.buildDirectory + "/war"
val fullDir = outDir + "/" + LIB