Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit eaef935

Browse files
committed
Create a auto-plugin to automatically add the pom files to the jars of plugins
1 parent c4057d6 commit eaef935

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

bootstrap/build.sbt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ assemblyJarName in assembly := "ChatOverflow.jar"
44

55
libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "1.1.1"
66
libraryDependencies += "org.jline" % "jline-terminal-jansi" % "3.11.0" // used for terminal width
7-
fork := true
7+
fork := true
8+
9+
packageBin / includePom := false

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Compile / packageBin := {
135135
}
136136

137137
Compile / unmanagedJars := (crossTarget.value ** "chatoverflow-gui*.jar").classpath
138+
packageBin / includePom := false
138139

139140
// ---------------------------------------------------------------------------------------------------------------------
140141
// UTIL
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.codeoverflow.chatoverflow.build
2+
3+
import sbt._
4+
import sbt.Keys._
5+
import sbt.plugins.JvmPlugin
6+
7+
/**
8+
* A sbt plugin to automatically include the dependencies of a sbt project in the jar as a pom file called "dependencies.pom".
9+
*/
10+
object PomInclusionPlugin extends AutoPlugin {
11+
12+
// Everything in autoImport will be visible to sbt project files
13+
// They can set this value to false if they don't want to include their dependencies as a pom file
14+
object autoImport {
15+
val includePom = settingKey[Boolean]("Whether to include a pom file inside the jar with all dependencies.")
16+
}
17+
import autoImport._
18+
19+
// We require to have the Compile configuration and the packageBin task to override
20+
override def requires = JvmPlugin
21+
override def trigger = allRequirements
22+
23+
// Adds our custom task before the packageBin task
24+
override val projectSettings: Seq[Def.Setting[_]] =
25+
inConfig(Compile)(Seq(
26+
Compile / packageBin := {
27+
addPomToOutput.value
28+
(Compile / packageBin).value
29+
}
30+
))
31+
32+
// Sets default values
33+
override def buildSettings: Seq[Def.Setting[_]] = inConfig(Compile)(
34+
includePom in packageBin := true
35+
)
36+
37+
// Just copies the pom resulted by makePom into the directory for compiled classes
38+
// That way the file will be included in the jar
39+
private lazy val addPomToOutput = Def.taskDyn {
40+
if ((includePom in packageBin).value) Def.task {
41+
val pomFile = (Compile / makePom).value
42+
43+
IO.copyFile(pomFile, new File((Compile / classDirectory).value, "dependencies.pom"))
44+
} else
45+
Def.task {} // if disabled, do nothing
46+
}
47+
}

0 commit comments

Comments
 (0)