diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt index 5a9cba74..292bb255 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/api/KobaltContext.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.internal.KobaltSettings import com.beust.kobalt.internal.PluginInfo import com.beust.kobalt.maven.DependencyManager import com.beust.kobalt.misc.KobaltExecutors +import java.io.File class KobaltContext(val args: Args) { var variant: Variant = Variant() @@ -47,4 +48,9 @@ class InternalContext { * will be disabled. */ var buildFileOutOfDate: Boolean = false + + /** + * The absolute directory of the current project. + */ + var absoluteDir: File? = null } \ No newline at end of file diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt index e4efb9e9..d7f8e831 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/build/BuildFile.kt @@ -23,4 +23,9 @@ class BuildFile(val path: Path, val name: String, val realPath: Path = path) { val dotKobaltDir: File get() = File(directory.parentFile.parentFile, KFiles.KOBALT_DOT_DIR).apply { mkdirs() } + + /** + * @return the absolute directory of this build file, assuming the build file is in $project/kobalt/src/Build.kt + */ + val absoluteDir = path.parent.parent.parent.toFile() } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt index 968056b6..6085ad61 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/DependencyManager.kt @@ -7,6 +7,7 @@ import com.beust.kobalt.maven.dependency.FileDependency import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KobaltExecutors import com.beust.kobalt.misc.log +import com.beust.kobalt.misc.warn import com.google.common.collect.ArrayListMultimap import java.io.File import java.util.* @@ -30,7 +31,15 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val val path = if (project?.directory != null) { val idPath = id.substring(FileDependency.PREFIX_FILE.length) if (! File(idPath).isAbsolute) { - File(project!!.directory, idPath) + // If the project directory is relative, we might not be in the correct directory to locate + // that file, so we'll use the absolute directory deduced from the build file path. Pick + // the first one that produces an actual file + val result = listOf(File(project!!.directory), Kobalt.context?.internalContext?.absoluteDir).map { + File(it, idPath) + }.first { + it.exists() + } + result } else { File(idPath) } @@ -119,7 +128,14 @@ class DependencyManager @Inject constructor(val executors: KobaltExecutors, val } } - val result2 = reorderDependencies(result).filter { + val reordered = reorderDependencies(result) + + val nonexistent = reordered.filter{ ! it.jarFile.get().exists() } + if (nonexistent.any()) { + warn("Nonexistent dependencies: $nonexistent") + } + + val result2 = reordered.filter { // Only keep existent files (nonexistent files are probably optional dependencies or parent poms // that point to other poms but don't have a jar file themselves) it.jarFile.get().exists() diff --git a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt index 47918c44..58ee7438 100644 --- a/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt +++ b/src/main/kotlin/com/beust/kobalt/app/BuildFileCompiler.kt @@ -73,6 +73,11 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b val pluginUrls = parsedBuildFile.pluginUrls val buildScriptJarFile = File(KFiles.findBuildScriptLocation(buildFile, SCRIPT_JAR)) + // + // Save the current build script absolute directory + // + context.internalContext.absoluteDir = buildFile.absoluteDir + // If the script jar files were generated by a different version, wipe them in case the API // changed in-between buildScriptJarFile.parentFile.let { dir -> @@ -96,6 +101,10 @@ public class BuildFileCompiler @Inject constructor(@Assisted("buildFiles") val b errorTaskResult = taskResult } } + + // Clear the absolute dir + context.internalContext.absoluteDir = null + } val pluginUrls = parsedBuildFiles.flatMap { it.pluginUrls } return FindProjectResult(projects, pluginUrls, if (errorTaskResult != null) errorTaskResult!! else TaskResult())