Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sbt._
- import Keys._
- import Defaults._
- /**
- * Provides a way to obtain the location of the main project artifact, and the artifacts of all its dependencies.
- */
- object Artifacts {
- val allTheArtifacts = TaskKey[Seq[(sbt.Artifact, java.io.File)]]("all-artifacts")
- val theMainArtifact = TaskKey[File]("main-artifact", "The main custom artifact that should be published")
- val artifactConf = config("Artifact") hide //use this to scope the create artifact to this config
- lazy val settings = inConfig(artifactConf)(Seq(
- allTheArtifacts <<= (thisProjectRef, buildStructure, streams) flatMap allArtifactsTask,
- theMainArtifact <<= artifactsTask,
- artifact in artifactConf <<= (name, version)((n,v) => Artifact(n + "-" + v, "zip", "zip")) //create the Artifact with project name and version, and zip type
- )) ++ addArtifact(artifact in artifactConf, theMainArtifact in artifactConf) ++ Seq(
- theMainArtifact in artifactConf <<= theMainArtifact in artifactConf dependsOn(packageBin in Compile)
- )
- def allArtifactsTask(projectRef: ProjectRef, structure: Load.BuildStructure, s: TaskStreams): Task[Seq[(sbt.Artifact, java.io.File)]] = {
- val projects = dependencies(projectRef, structure, s)
- s.log.info("found projects %s".format(projects))
- projects flatMap {ref => packagedArtifact in Compile in ref.project in packageBin get structure.data } join
- }
- /**
- * Gets the given project's dependencies. This is done recursively, so the dependencies of a dependency are also part of the result.
- * The result may contain duplicates, these are not filtered out at the moment.
- */
- def dependencies(projectRef: ProjectRef, structure: Load.BuildStructure, s: TaskStreams): Seq[ProjectRef] = {
- val deps = Project.getProject(projectRef, structure).toSeq.flatMap(_.dependencies)
- s.log.info("got deps %s for project ref %s".format(deps, projectRef))
- deps flatMap { ref => ref.project +: dependencies(ref.project, structure, s)}
- }
- def artifactsTask = (allTheArtifacts in artifactConf, target in Compile, streams) map {
- (arts, t, s) => {s.log.info("executing task with artifacts %s".format(arts.map(a => a._2)))}
- val result = new File(t, "myFile") //just create a simple file in the target directory for illustration
- result.createNewFile()
- result
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement