2018-11-20 13:15:26 +01:00
package coursier.sbtcoursiershared
2019-02-26 13:29:55 +01:00
import java.io.File
2018-11-22 14:14:35 +01:00
2019-04-04 11:12:11 +02:00
import coursier. { Credentials => LegacyCredentials }
2019-04-25 16:31:37 +02:00
import lmcoursier.credentials.Credentials
import lmcoursier. { CoursierDependencyResolution , FallbackDependency }
import lmcoursier.definitions. { CacheLogger , Configuration , Project , Publication }
2019-04-24 18:20:32 +02:00
import lmcoursier.internal.SbtCoursierCache
2018-11-21 11:18:35 +01:00
import sbt. { AutoPlugin , Classpaths , Compile , Setting , TaskKey , Test , settingKey , taskKey }
import sbt.Keys._
2019-08-14 16:23:43 +02:00
import sbt.librarymanagement.DependencyBuilders.OrganizationArtifactName
import sbt.librarymanagement. { ModuleID , Resolver , URLRepository }
2018-11-20 13:15:26 +01:00
object SbtCoursierShared extends AutoPlugin {
2020-05-05 19:59:59 +02:00
lmcoursier . CoursierConfiguration . checkLegacyCache ( )
2018-11-20 13:15:26 +01:00
override def trigger = allRequirements
override def requires = sbt . plugins . JvmPlugin
object autoImport {
2018-11-20 17:17:53 +01:00
val coursierGenerateIvyXml = settingKey [ Boolean ] ( "" )
2018-11-20 13:15:26 +01:00
val coursierProject = TaskKey [ Project ] ( "coursier-project" )
val coursierInterProjectDependencies = TaskKey [ Seq [ Project ] ] ( "coursier-inter-project-dependencies" , "Projects the current project depends on, possibly transitively" )
2019-07-11 20:24:06 +02:00
val coursierExtraProjects = TaskKey [ Seq [ Project ] ] ( "coursier-extra-projects" , "" )
2018-11-20 17:17:53 +01:00
val coursierPublications = TaskKey [ Seq [ ( Configuration , Publication ) ] ] ( "coursier-publications" )
2018-11-20 18:01:24 +01:00
val coursierKeepPreloaded = settingKey [ Boolean ] ( "Whether to take into account sbt preloaded repositories or not" )
val coursierReorderResolvers = settingKey [ Boolean ] (
"Whether resolvers should be re-ordered so that typically slow ones are given a lower priority"
)
val coursierResolvers = taskKey [ Seq [ Resolver ] ] ( "" )
val coursierRecursiveResolvers = taskKey [ Seq [ Resolver ] ] ( "Resolvers of the current project, plus those of all from its inter-dependency projects" )
2018-11-21 11:18:35 +01:00
val coursierSbtResolvers = taskKey [ Seq [ Resolver ] ] ( "" )
2018-11-21 13:21:41 +01:00
val coursierFallbackDependencies = taskKey [ Seq [ FallbackDependency ] ] ( "" )
2018-11-22 13:04:35 +01:00
val mavenProfiles = settingKey [ Set [ String ] ] ( "" )
2019-08-14 16:23:43 +02:00
val versionReconciliation = taskKey [ Seq [ ModuleID ] ] ( "" )
2018-11-22 13:52:59 +01:00
2020-05-19 14:50:06 +02:00
private [ coursier ] val actualCoursierCredentials = TaskKey [ Map [ String , LegacyCredentials ] ] ( "coursierCredentials" , "" )
2018-11-22 13:52:59 +01:00
val coursierUseSbtCredentials = settingKey [ Boolean ] ( "" )
2019-04-04 11:12:11 +02:00
@deprecated ( "Use coursierExtraCredentials rather than coursierCredentials" , "1.1.0-M14" )
2020-05-19 14:50:06 +02:00
val coursierCredentials = actualCoursierCredentials
2019-04-03 16:13:18 +02:00
val coursierExtraCredentials = taskKey [ Seq [ Credentials ] ] ( "" )
2018-11-22 14:14:35 +01:00
2019-02-26 13:29:55 +01:00
val coursierLogger = taskKey [ Option [ CacheLogger ] ] ( "" )
2018-11-22 14:14:35 +01:00
val coursierCache = settingKey [ File ] ( "" )
2018-12-12 11:19:05 +01:00
val sbtCoursierVersion = Properties . version
2018-11-20 13:15:26 +01:00
}
import autoImport._
2018-11-20 17:17:53 +01:00
def publicationsSetting ( packageConfigs : Seq [ ( sbt . Configuration , Configuration ) ] ) : Setting [ _ ] =
coursierPublications : = ArtifactsTasks . coursierPublicationsTask ( packageConfigs : _ * ) . value
2019-04-04 11:35:12 +02:00
override def globalSettings : Seq [ Setting [ _ ] ] =
Seq (
coursierUseSbtCredentials : = true ,
2020-05-19 14:50:06 +02:00
actualCoursierCredentials : = Map . empty ,
2019-04-04 11:35:12 +02:00
coursierExtraCredentials : = Nil
)
2018-11-20 18:01:24 +01:00
override def buildSettings : Seq [ Setting [ _ ] ] =
Seq (
coursierReorderResolvers : = true ,
2018-11-22 13:52:59 +01:00
coursierKeepPreloaded : = false ,
2019-02-26 13:29:55 +01:00
coursierLogger : = None ,
2019-04-25 16:31:37 +02:00
coursierCache : = CoursierDependencyResolution . defaultCacheLocation
2018-11-20 18:01:24 +01:00
)
2018-11-21 11:18:35 +01:00
private val pluginIvySnapshotsBase = Resolver . SbtRepositoryRoot . stripSuffix ( "/" ) + "/ivy-snapshots"
2018-11-20 18:01:24 +01:00
override def projectSettings = settings ( pubSettings = true )
def settings ( pubSettings : Boolean ) =
2018-11-20 17:17:53 +01:00
Seq [ Setting [ _ ] ] (
2018-11-20 17:39:19 +01:00
clean : = {
val noWarningPlz = clean . value
SbtCoursierCache . default . clear ( )
} ,
2018-11-20 17:17:53 +01:00
coursierGenerateIvyXml : = true ,
coursierProject : = InputsTasks . coursierProjectTask . value ,
2019-07-11 20:24:06 +02:00
coursierInterProjectDependencies : = InputsTasks . coursierInterProjectDependenciesTask . value ,
coursierExtraProjects : = InputsTasks . coursierExtraProjectsTask . value
2018-11-20 18:01:24 +01:00
) ++ {
if ( pubSettings )
Seq (
publicationsSetting ( Seq ( Compile , Test ) . map ( c => c -> Configuration ( c . name ) ) )
)
else
Nil
} ++ Seq (
2018-11-20 17:49:20 +01:00
// Tests artifacts from Maven repositories are given this type.
// Adding it here so that these work straightaway.
2018-11-20 18:01:24 +01:00
classpathTypes += "test-jar" , // FIXME Should this go in buildSettings?
coursierResolvers : = RepositoriesTasks . coursierResolversTask . value ,
coursierRecursiveResolvers : = RepositoriesTasks . coursierRecursiveResolversTask . value ,
2018-11-21 11:18:35 +01:00
coursierSbtResolvers : = {
// TODO Add docker-based integration test for that, see https://github.com/coursier/coursier/issues/632
val resolvers =
sbt . Classpaths . bootRepositories ( appConfiguration . value ) . toSeq . flatten ++ // required because of the hack above it seems
externalResolvers . in ( updateSbtClassifiers ) . value
val pluginIvySnapshotsFound = resolvers . exists {
case repo : URLRepository =>
repo
. patterns
. artifactPatterns
. headOption
. exists ( _ . startsWith ( pluginIvySnapshotsBase ) )
case _ => false
}
val resolvers0 =
if ( pluginIvySnapshotsFound && ! resolvers . contains ( Classpaths . sbtPluginReleases ) )
resolvers : + Classpaths.sbtPluginReleases
else
resolvers
if ( SbtCoursierShared . autoImport . coursierKeepPreloaded . value )
resolvers0
else
resolvers0 . filter { r =>
! r . name . startsWith ( "local-preloaded" )
}
2018-11-21 13:21:41 +01:00
} ,
coursierFallbackDependencies : = InputsTasks . coursierFallbackDependenciesTask . value ,
2018-11-21 15:29:50 +01:00
ivyConfigurations : = {
val confs = ivyConfigurations . value
val names = confs . map ( _ . name ) . toSet
// Yes, adding those back in sbt 1.0. Can't distinguish between config test (whose jars with classifier tests ought to
// be added), and sources / docs else (if their JARs are in compile, they would get added too then).
val extraSources =
if ( names ( "sources" ) )
None
else
Some (
sbt . Configuration . of (
id = "Sources" ,
name = "sources" ,
description = "" ,
isPublic = true ,
extendsConfigs = Vector . empty ,
transitive = false
)
)
val extraDocs =
if ( names ( "docs" ) )
None
else
Some (
sbt . Configuration . of (
id = "Docs" ,
name = "docs" ,
description = "" ,
isPublic = true ,
extendsConfigs = Vector . empty ,
transitive = false
)
)
confs ++ extraSources . toSeq ++ extraDocs . toSeq
2018-11-22 13:04:35 +01:00
} ,
2019-08-14 16:23:43 +02:00
mavenProfiles : = Set . empty ,
versionReconciliation : = Seq . empty
2018-11-20 18:01:24 +01:00
) ++ {
if ( pubSettings )
2020-05-19 14:30:05 +02:00
IvyXmlGeneration . generateIvyXmlSettings
2018-11-20 18:01:24 +01:00
else
Nil
}
2018-11-20 13:15:26 +01:00
}