Skip to content

Commit 20351b4

Browse files
committed
feat: build jars by default for jvm projects
Signed-off-by: Sam Gammon <sam@elide.dev>
1 parent 79f535b commit 20351b4

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

packages/builder/src/main/kotlin/elide/tooling/jvm/JarBuildConfigurator.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import elide.tooling.AbstractTool
4141
import elide.tooling.config.BuildConfigurator
4242
import elide.tooling.config.BuildConfigurator.*
4343
import elide.tooling.project.ElideProject
44+
import elide.tooling.project.SourceSetLanguage
45+
import elide.tooling.project.SourceSetType
4446
import elide.tooling.project.manifest.ElidePackageManifest.*
4547

4648
/**
@@ -303,9 +305,11 @@ internal class JarBuildConfigurator : BuildConfigurator {
303305
}
304306

305307
override suspend fun contribute(state: ElideBuildState, config: BuildConfiguration) {
308+
var hasMainJar = false
306309
state.manifest.artifacts.entries.filter { it.value is Jar }.forEach { (name, jartifact) ->
307310
config.actionScope.apply {
308311
config.taskGraph.apply {
312+
if (name == "main" || name == "jar") hasMainJar = true
309313
jar(
310314
name,
311315
state,
@@ -320,5 +324,36 @@ internal class JarBuildConfigurator : BuildConfigurator {
320324
}
321325
}
322326
}
327+
if (!hasMainJar) {
328+
val mainSources = state.project.sourceSets.find(SourceSetType.Sources).firstOrNull()
329+
val langs = mainSources?.languages ?: emptySet()
330+
if (langs.isNotEmpty()) {
331+
if (SourceSetLanguage.Kotlin in langs || SourceSetLanguage.Java in langs) {
332+
// we are configuring a build with the following conditions:
333+
// 1) there is a main source set which uses one of (Kotlin or Java), but
334+
// 2) there is no explicitly configured main jar (a jar task called 'main' or 'jar'),
335+
// so we can create one on behalf of the user.
336+
config.actionScope.apply {
337+
val jartifact = Jar(
338+
name = "main",
339+
sources = listOf("main"),
340+
options = JarOptions(
341+
entrypoint = state.manifest.jvm?.main?.ifEmpty { null }?.ifBlank { null },
342+
),
343+
)
344+
config.taskGraph.apply {
345+
jar(
346+
name = "jar",
347+
state = state,
348+
config = config,
349+
dependencies = taskDepsForJar(state),
350+
artifact = jartifact,
351+
srcSets = resolveSourceSetsForJar(state, jartifact),
352+
)
353+
}
354+
}
355+
}
356+
}
357+
}
323358
}
324359
}

0 commit comments

Comments
 (0)