Skip to content

daggerok/gradle-scala-application-howto

Repository files navigation

gradle-scala-application-howto gradle-scala-application-howto

Because I don't know sbt...

./gradlew clean test npm_i npm_run_build

[[toc]]

gradle init

initialize new scala project:

mkdir gradle-scala-application-howto cd gradle-scala-application-howto/ gradle init --type scala-library --package com.github.daggerok --project-name gradle-scala-application-howto --dsl kotlin

gradle fatJar

add to build.gradle.kts file fatJar task definition:

tasks { register<Jar>("fatJar") { archiveClassifier.set("all") duplicatesStrategy = DuplicatesStrategy.EXCLUDE manifest { attributes("Main-Class" to "com.github.daggerok.Main") } from(configurations.runtimeClasspath.get() .onEach { println("add from dependencies: ${it.name}") } .map { if (it.isDirectory) it else zipTree(it) }) val sourcesMain = sourceSets.main.get() sourcesMain.allSource.forEach { println("add from sources: ${it.name}") } from(sourcesMain.output) } }

then build and run, like so:

./gradlew clean fatJar java -jar build/libs/*-all.jar

gradle tests output

add to build.gradle.kts file these lines for better developer experience on tests execution:

import org.gradle.api.tasks.testing.logging.TestLogEvent.* tasks { withType<Test> { testLogging { showExceptions = true showStandardStreams = true events(PASSED, SKIPPED, FAILED) } } }

gradle npm integration

add to build.gradle.kts file these lines for better developer experience on tests execution:

plugins { // Add Gradle NodeJS support id("com.moowork.node") version "1.3.1" } node { download = true }

prepare everything together with npm scrips and use gradle instead:

./gradlew npm_i # npm i ./gradlew npm_run build # npm run build

publish project to GitHub

create .gitignore file:

.idea/ *.iml *.ipr *.iws *.log* .gradle/ build/ /out/ .DS_Store node_modules/ .vuepress/dist/ 

GitHub actions

just see .github/workflows/ci.yaml file as a the reference...