diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt index badb7b48..c83e2704 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/JarUtils.kt @@ -34,18 +34,22 @@ public class JarUtils { val path = spec.toString() spec.toFiles(directory + "/" + file.from).forEach { source -> if (source.isDirectory) { + log(2, "Writing contents of directory ${source}") + // Directory var name = path if (!name.isEmpty()) { if (!name.endsWith("/")) name += "/" val entry = JarEntry(name) entry.time = source.lastModified() - outputStream.putNextEntry(entry) - outputStream.closeEntry() + try { + outputStream.putNextEntry(entry) + } finally { + outputStream.closeEntry() + } } - val fileSpecs: List = source.listFiles().map { IFileSpec.FileSpec(it.name) } - val subFiles = IncludedFile(From(file.from), To(file.to), fileSpecs) - addSingleFile(directory, subFiles, outputStream, expandJarFiles) + val includedFile = IncludedFile(From(source.path), To(""), listOf(IFileSpec.Glob("**"))) + addSingleFile(directory, includedFile, outputStream, expandJarFiles) } else { if (expandJarFiles and source.name.endsWith(".jar")) { log(2, "Writing contents of jar file ${source}") diff --git a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt index 671d9079..33240a2d 100644 --- a/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt +++ b/src/main/kotlin/com/beust/kobalt/plugin/packaging/PackagingPlugin.kt @@ -4,16 +4,14 @@ import com.beust.kobalt.IFileSpec import com.beust.kobalt.IFileSpec.FileSpec import com.beust.kobalt.IFileSpec.Glob import com.beust.kobalt.TaskResult -import com.beust.kobalt.api.ConfigPlugin -import com.beust.kobalt.api.Kobalt -import com.beust.kobalt.api.KobaltContext -import com.beust.kobalt.api.Project +import com.beust.kobalt.api.* import com.beust.kobalt.api.annotation.Directive import com.beust.kobalt.api.annotation.ExportedProjectProperty import com.beust.kobalt.api.annotation.Task import com.beust.kobalt.glob import com.beust.kobalt.internal.JvmCompilerPlugin import com.beust.kobalt.maven.DependencyManager +import com.beust.kobalt.maven.IClasspathDependency import com.beust.kobalt.maven.LocalRepo import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors @@ -161,14 +159,25 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana if (jar.fatJar) { log(2, "Creating fat jar") - listOf(dependencyManager.transitiveClosure(project.compileDependencies), - dependencyManager.transitiveClosure(project.compileRuntimeDependencies)).forEach { dep -> - dep.map { it.jarFile.get() }.forEach { - if (!isExcluded(it, jar.excludes)) { - allFiles.add(IncludedFile(arrayListOf(FileSpec(it.path)))) - } - } - } + val seen = hashSetOf() + val dependentProjects = project.projectProperties.get(JvmCompilerPlugin.DEPENDENT_PROJECTS) + as List + listOf(dependencyManager.calculateDependencies(project, context, dependentProjects, + project.compileDependencies), + dependencyManager.calculateDependencies(project, context, dependentProjects, + project.compileRuntimeDependencies)) + .forEach { deps : List -> + deps.map { + it.jarFile.get() + }.forEach { file : File -> + if (! seen.contains(file.name)) { + seen.add(file.name) + if (!isExcluded(file, jar.excludes)) { + allFiles.add(IncludedFile(arrayListOf(FileSpec(file.path)))) + } + } + } + } } //