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

Commit 346d0b6

Browse files
committed
Add exact gui jar file to the classpath instead of a wildcard
With the wildcard IntelliJ would only add the gui jar to the classpath after a reload of the sbt project, because the gui jar does only exist after an advanced build, but not at the normal import time. With this commit IntelliJ will try to add the jar on the first reload/import even tho it currently doesn't exist. That's not a problem, IntelliJ will just ignore the nonexistent jar and once the advanced build has been run IntelliJ will add the jar to the classpath without a reload. Note that a reload is still required after the gui version number has changed! This commit also drops the scala version suffix in the name of the gui jar because it doesn't contain any scala code and having the scala suffix in the name does not make any sense.
1 parent 3d592d1 commit 346d0b6

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ deployDev := BootstrapUtility.prepareDevDeploymentTask(streams.value.log, scalaM
136136
gui := new GUIUtility(streams.value.log).guiTask(guiProjectPath.value, streams.value.cacheDirectory / "gui")
137137

138138
Compile / packageBin := {
139-
new GUIUtility(streams.value.log).packageGUITask(guiProjectPath.value, scalaMajorVersion, crossTarget.value)
139+
new GUIUtility(streams.value.log).packageGUITask(guiProjectPath.value, crossTarget.value)
140140
(Compile / packageBin).value
141141
}
142142

143-
Compile / unmanagedJars := (crossTarget.value ** "chatoverflow-gui*.jar").classpath
143+
Compile / unmanagedJars := new GUIUtility(streams.value.log).getGUIJarClasspath(guiProjectPath.value, crossTarget.value)
144144
packageBin / includePom := false
145145

146146
fork in run := true // Start ChatOverflow in it's own java process when starting it with 'sbt run'

build/src/main/scala/org/codeoverflow/chatoverflow/build/GUIUtility.scala

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import java.util.jar.Manifest
55

66
import com.fasterxml.jackson.databind.ObjectMapper
77
import org.codeoverflow.chatoverflow.build.BuildUtils.withTaskInfo
8-
import sbt.internal.util.ManagedLogger
8+
import sbt.Keys.Classpath
9+
import sbt.internal.util.{Attributed, ManagedLogger}
910
import sbt.util.{FileFunction, FilesInfo}
1011

1112
import scala.io.Source
@@ -88,7 +89,7 @@ class GUIUtility(logger: ManagedLogger) {
8889
}
8990
}
9091

91-
def packageGUITask(guiProjectPath: String, scalaMajorVersion: String, crossTargetDir: File): Unit = {
92+
def packageGUITask(guiProjectPath: String, crossTargetDir: File): Unit = {
9293
val dir = new File(guiProjectPath, "dist")
9394
if (!dir.exists()) {
9495
logger info "GUI hasn't been compiled. Won't create a jar for it."
@@ -100,9 +101,16 @@ class GUIUtility(logger: ManagedLogger) {
100101
// contains tuples with the actual file as the first value and the name with directory in the jar as the second value
101102
val jarEntries = files.map(file => file -> s"/chatoverflow-gui/${dir.toURI.relativize(file.toURI).toString}")
102103

103-
val guiVersion = getGUIVersion(guiProjectPath).getOrElse("unknown")
104+
sbt.IO.jar(jarEntries, getGUIJarFile(guiProjectPath, crossTargetDir), new Manifest())
105+
}
104106

105-
sbt.IO.jar(jarEntries, new File(crossTargetDir, s"chatoverflow-gui_$scalaMajorVersion-$guiVersion.jar"), new Manifest())
107+
def getGUIJarClasspath(guiProjectPath: String, crossTargetDir: File): Classpath = {
108+
Attributed.blankSeq(Seq(getGUIJarFile(guiProjectPath, crossTargetDir)))
109+
}
110+
111+
private def getGUIJarFile(guiProjectPath: String, crossTargetDir: File): File = {
112+
val guiVersion = getGUIVersion(guiProjectPath).getOrElse("unknown")
113+
new File(crossTargetDir, s"chatoverflow-gui-$guiVersion.jar")
106114
}
107115

108116
private def getGUIVersion(guiProjectPath: String): Option[String] = {

0 commit comments

Comments
 (0)