From f1a025036fa1ae3974bac491fe6cfec2b5a282aa Mon Sep 17 00:00:00 2001 From: Avently Date: Wed, 21 Mar 2018 18:25:44 +0300 Subject: [PATCH] Added "offline" argument to prevent remote resolving of dependencies --- .../src/main/kotlin/com/beust/kobalt/Args.kt | 3 +++ .../src/main/kotlin/com/beust/kobalt/maven/aether/Booter.kt | 4 +++- .../com/beust/kobalt/maven/aether/KobaltMavenResolver.kt | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt index d1cdc078d..372f1ba12 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/Args.kt @@ -61,6 +61,9 @@ class Args { @Parameter(names = arrayOf("--noIncremental"), description = "Turn off incremental builds") var noIncremental: Boolean = false + @Parameter(names = arrayOf("--offline"), description = "Don't try to download dependencies even if there is no cached version") + var offline: Boolean = false + @Parameter(names = arrayOf("--plugins"), description = "Comma-separated list of plug-in Maven id's") var pluginIds: String? = null diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Booter.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Booter.kt index e3b52dcd8..02917929e 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Booter.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/Booter.kt @@ -2,6 +2,7 @@ package com.beust.kobalt.maven.aether import com.beust.kobalt.internal.KobaltSettings import com.google.common.eventbus.EventBus +import com.beust.kobalt.Args import org.eclipse.aether.DefaultRepositorySystemSession import org.eclipse.aether.RepositorySystem import org.eclipse.aether.repository.LocalRepository @@ -32,8 +33,9 @@ object Booter { // } fun newRepositorySystemSession(system: RepositorySystem, repo: File, settings: KobaltSettings, - eventBus: EventBus): DefaultRepositorySystemSession { + args: Args, eventBus: EventBus): DefaultRepositorySystemSession { val session = MavenRepositorySystemUtils.newSession(settings) + session.isOffline = args.offline val localRepo = LocalRepository(repo.absolutePath) session.localRepositoryManager = system.newLocalRepositoryManager(session, localRepo) diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt index 06a7c993d..f5fcde595 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/maven/aether/KobaltMavenResolver.kt @@ -141,7 +141,7 @@ class KobaltMavenResolver @Inject constructor(val settings: KobaltSettings, fun create(id: String, optional: Boolean) = AetherDependency(DefaultArtifact(id), optional, args) private val system = Booter.newRepositorySystem() - private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, eventBus) + private val session = Booter.newRepositorySystemSession(system, localRepo.localRepo, settings, args, eventBus) private fun createRepo(hostConfig: HostConfig) : RemoteRepository { val builder = RemoteRepository.Builder(hostConfig.name, "default", hostConfig.url)