How can I add local resources using Gradle Kotlin-DSL - gradle

I'm trying to test gradle 5 using kotlin DSL.
I created a lib, and built it as below:
Hasans-Air:blogiclib h_ajsf$ gradle init --type=kotlin-library
Starting a Gradle Daemon, 1 busy Daemon could not be reused, use --status for details
Select build script DSL:
1: groovy
2: kotlin
Enter selection (default: kotlin) [1..2] 2
Project name (default: blogiclib): 
Source package (default: blogiclib): 
**BUILD SUCCESSFUL** in 16s
2 actionable tasks: 2 executed
Hasans-Air:blogiclib h_ajsf$ ls
build.gradle.kts gradlew settings.gradle.kts
gradle gradlew.bat src
Hasans-Air:blogiclib h_ajsf$ code .
Hasans-Air:blogiclib h_ajsf$ gradle build
Then I got the output file generated as: build\libs\blogiclib.jar
The Library.kt file generated is:
package blogiclib
class Library {
fun someLibraryMethod(): Boolean {
return true
}
}
And the build.gradle.kts generated is:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.10")
}
repositories {
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
Then I generated a kotlin app and tested it as below:
Hasans-Air:gradle h_ajsf$ gradle init --type=kotlin-application
Starting a Gradle Daemon (subsequent builds will be faster)
Select build script DSL:
1: groovy
2: kotlin
Enter selection (default: kotlin) [1..2] 2
Project name (default: gradle): blogic
Source package (default: blogic): 
**BUILD SUCCESSFUL** in 25s
2 actionable tasks: 2 executed
Hasans-Air:gradle h_ajsf$ ls
build.gradle.kts gradlew settings.gradle.kts
gradle gradlew.bat src
Hasans-Air:gradle h_ajsf$ code .
Hasans-Air:gradle h_ajsf$ gradle run
**BUILD SUCCESSFUL** in 6m 4s
3 actionable tasks: 3 executed
Hasans-Air:gradle h_ajsf$ gradle run
**> Task :run**
Hello world.
Then I added the previously generated lib blogiclib.jar to the folder: main\resources
And made my App.kt file as:
package blogic
import blogiclib.LibraryKt
class App {
val greeting: String
get() {
return "Hello world."
}
}
fun main(args: Array<String>) {
println("${App().greeting} = someLibraryMethod()")
}
And its build.gradle.kts based on my understanding from here as:
plugins {
id("org.jetbrains.kotlin.jvm").version("1.3.10")
application
}
repositories {
jcenter()
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.jetbrains.kotlin:kotlin-test")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
}
application {
mainClassName = "blogic.AppKt"
}
task<JavaCompile>("compile") {
source = fileTree(file("src/main/resources/blogiclib.jar"))
}
But at compiling I got the below error:
Hasans-Air:gradle h_ajsf$ gradle run
e: /Users/h_ajsf/Documents/gradle/src/main/kotlin/blogic/App.kt: (6, 8): Unresolved reference: blogiclib
**> Task :compileKotlin** FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileKotlin'.
> Compilation error. See log for more details
* Try:
Run with **--stacktrace** option to get the stack trace. Run with **--info** or **--debug** option to get more log output. Run with **--scan** to get full insights.
* Get more help at **https://help.gradle.org**
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0/userguide/command_line_interface.html#sec:command_line_warnings
**BUILD FAILED** in 1s
2 actionable tasks: 2 executed
UPDATE
In reference to the comments received, I did the below:
Moved the library file to folder src/main/libs:
Added the below code to the build.gradle.kts:
configurations {
create("externalLibs")
}
dependencies {
"externalLibs"(files("src/main/libs/blogiclib.jar"))
}
instead of:
task<JavaCompile>("compile") {
source = fileTree(file("src/main/resources/blogiclib.jar"))
}
but still getting the same error :(

You can include all jar files in some folders as follows:
dependencies {
implementation(fileTree("libs/compile"))
compileOnly(fileTree("libs/provided"))
}
Alternatively, select specific files:
repositories {
flatDir {
dirs("libs/compile")
dirs("libs/provided")
}
}
dependencies {
implementation(":gson-2.8.5")
compileOnly(":javaee-api-8.0")
}

Related

`gradlew` compiling successfully without checking for symbols on the classpath

I am using a gradle project to build a Jenkins shared library. I have a build.gradle with following content:
// Apply the groovy plugin to add support for groovy
apply plugin: 'groovy'
sourceSets {
main {
groovy {
srcDirs = ['src', 'vars']
}
}
test {
groovy {
srcDirs = ['test']
}
}
}
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
jcenter()
// You can declare any Maven/Ivy/file repository here.
maven {
url "https://repo.jenkins-ci.org/releases/"
}
}
// In this section you declare the dependencies for your production and test code
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.5.6'
compile 'org.apache.ivy:ivy:2.4.0'
testCompile 'junit:junit:4.12'
}
Inside my vars/ directory I have the following source code in it:
def call(Map params) {
2 pipeline {
3 agent none
4
5 stages {
6 stage('Build') {
7 agent { label 'maven'}
8 steps {
9 logError 'Hello world'
10 }
11 }
12 }
13 }
14 }
When I run ./gradlew build or ./gradlew compileGroovy the compilation goes through fine. It looks it is only doing syntax validation and does not care about linking the symbols such as pipeline or agent etc. Am I understanding it correctly?
Okay I think I figured it out. This is happening because groovyc (in this case gradlew compileGroovy is producing a byte code that does not translate high level language to its bytecode equivalent. Instead each line is replaced by a method dispatch. So line 2 in the code above will get replaced with
getMetaClass().invokeMethod(this, 'pipeline', closure)
This causes compile time check on pipeline symbol to be promoted to a runtime error.

Gradle can't find tests anymore after Spring Boot upgrade to 2.3.2

We recently upgraded our Kotlin Spring Boot project so Spring Boot 2.3.2 and since then it seems that gradle can no longer pick up any tests.
We were using the gradle wrapper 5.6.2 and upgraded to 6.3 even though the documentation stated that 5.6.x should work as well. The Gradle upgrade did not help and gradle still can not pick up any tests, when I downgrade to 2.2.3 it works fine. We are using Kotest, Junit5 and an embedded mongodb for our tests.
plugins {
val kotlinVersion = "1.3.50"
kotlin("jvm") version kotlinVersion
kotlin("plugin.spring") version kotlinVersion
id("org.springframework.boot") version "2.3.2.RELEASE"
id("io.spring.dependency-management") version "1.0.9.RELEASE"
id("jacoco")
}
dependencyManagement {
dependencies {
dependency("net.logstash.logback:logstash-logback-encoder:6.1")
dependency("com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0")
val kotlintestVersion = "3.4.2"
dependency("io.kotlintest:kotlintest-runner-junit5:$kotlintestVersion")
dependency("io.kotlintest:kotlintest-extensions-spring:$kotlintestVersion")
dependency("io.kotlintest:kotlintest-assertions:$kotlintestVersion")
}
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-security")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
testImplementation("org.assertj:assertj-core")
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude(group = "org.junit.vintage", module = "junit-vintage-engine")
}
testImplementation("org.springframework.amqp:spring-rabbit-test")
testImplementation("org.springframework.security:spring-security-test")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin")
testImplementation("io.kotlintest:kotlintest-runner-junit5")
testImplementation("io.kotlintest:kotlintest-extensions-spring")
testImplementation("io.kotlintest:kotlintest-assertions")
}
val jacocoTask = tasks.withType<JacocoReport> {
reports {
xml.isEnabled = true
}
}
tasks.withType<Test> {
doFirst {
environment("SPRING_DATA_MONGODB_PORT", "${project.mongo.port}")
}
this.extra.set("runWithMongoDb", true)
useJUnitPlatform()
finalizedBy(jacocoTask)
}
mongo {
setPort("RANDOM")
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
freeCompilerArgs = listOf("-XXLanguage:+InlineClasses")
}
Any hint on what I might be doing wrong?
One of our very simple tests:
#SpringBootTest
#ExperimentalUnsignedTypes
class HardwareServiceApplicationSpec : FunSpec() {
override fun listeners(): List<TestListener> {
return listOf(SpringListener)
}
#Autowired
private lateinit var rmqMessageReceiver: RmqMessageReceiver
init {
test("the messageReceiver bean is created on application startup") {
assertThat(rmqMessageReceiver).isNotNull()
}
}
}
The log output of the test also doesn't help me a lot:
> Task :test
file or directory 'C:\Users\Pia Gerhofer\Projects\hw-service-v2\build\classes\java\test', not found
Excluding []
Caching disabled for task ':test' because:
Build cache is disabled
Task ':test' is not up-to-date because:
Task.upToDateWhen is false.
Extracting Mongo binaries...
Starting Mongod 4.0.2 on port 55319...
start de.flapdoodle.embed.mongo.config.MongodConfigBuilder$ImmutableMongodConfig#7f4e7fe1
Mongod started.
file or directory 'C:\Users\Pia Gerhofer\Projects\hw-service-v2\build\classes\java\test', not found
Starting process 'Gradle Test Executor 3'. Working directory: C:\Users\Pia Gerhofer\Projects\hw-service-v2 Command: C:\Program Files\Java\jdk-11.0.5\bin\java.exe -Dorg.gradle.native=false -javaagent:build/tmp/expandedArchives/org.jacoco.agent-0.8.5.jar_6a2df60c47de373ea127d14406367999/jacocoagent.jar=destfile=build/jacoco/test.exec,append=true,inclnolocationclasses=false,dumponexit=true,output=file,jmx=false #C:\Users\Pia Gerhofer\AppData\Local\Temp\gradle-worker-classpath2455123809837509056txt -Xmx512m -Dfile.encoding=windows-1252 -Duser.country=AT -Duser.language=de -Duser.variant -ea worker.org.gradle.process.internal.worker.GradleWorkerMain 'Gradle Test Executor 3'
Successfully started process 'Gradle Test Executor 3'
Gradle Test Executor 3 started executing tests.
> Task :test
~~~ Project Configuration ~~~
Gradle Test Executor 3 STANDARD_OUT
~~~ Project Configuration ~~~
-> Parallelism: 1 thread
-> Parallelism: 1 thread
-> Test order: LexicographicSpecExecutionOrder
-> Test order: LexicographicSpecExecutionOrder
-> Soft assertations: False
-> Soft assertations: False
-> Write spec failure file: False
-> Write spec failure file: False
-> Fail on ignored tests: False
-> Fail on ignored tests: False
-> Extensions
-> Extensions
- io.kotlintest.extensions.SystemPropertyTagExtension
- io.kotlintest.extensions.SystemPropertyTagExtension
- io.kotlintest.extensions.RuntimeTagExtension
- io.kotlintest.extensions.RuntimeTagExtension
Gradle Test Executor 3 finished executing tests.
> Task :test FAILED
So I see no exception or any other problem in the logs even though I get the following:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [com.tractive.hwservice.HardwareServiceApplicationSpec](filter.includeTestsMatching)
Any help is appreciated, I already tried various gradle versions, no combination worked so far. A colleague told me I might have to use a different test runner but I can't find anything concerning that in the upgrade guide/documentation.
Interestingly enough I upgraded another of our services to the latest spring boot version, which uses gradle wrapper 6.4 and the tests work as expected there.
Finally got it to work with any of the Gradle versions, tried it with (5.6.x, 6.3, 6.4, 6.5 and 6.6).
The thing we were missing is updating the kotlin plugin.spring version. After we updated that to 1.3.72 instead of 1.3.50 everything was working as expected.

How can I get Gradle to build dependencies before running my task?

Background: I am trying to hook the compiler for my own domain-specific language into Gradle. The DSL is compiled to Java source code, so I have built a task that runs before the Java compiler. The compiler cannot currently handle multiple projects with dependencies, so I'm trying to add that.
My DSL has packages like Java that get mapped to identical Java packages. The same should be true for projects. In that case, for each project, the DSL sources get compiled to Java source code, as well as meta-data (a JSON file per compiled class, containing information from the DSL's type system that cannot be mapped to Java types). When project A depends on B, the DSL compilation process for A needs the meta-data files from B. That meta-data should be packaged as resources into the JAR file together with the generated and compiled Java code, as well as possibly hand-written and compiled Java code.
FoobarPlugin.groovy:
class FoobarPlugin implements Plugin<Project> {
#Override
void apply(Project project) {
// create the compileFoobar task
CompileFoobarTask task = project.getTasks().create('compileFoobar', CompileFoobarTask.class);
task.group = 'build';
task.setDescription('Compiles Foobar to Java code.');
task.sourceDirectory = new File(project.projectDir, "src/main/foobar");
task.outputDirectory = new File(project.getBuildDir(), "foobar-java");
// compileFoobar must run before compiling Java code
project.tasks.compileJava.dependsOn(task);
// add the task's output folders as Java source folders
project.sourceSets.main.java.srcDirs += task.outputDirectory;
project.sourceSets.main.resources.srcDirs += task.outputDirectory;
project.sourceSets.test.java.srcDirs += task.outputDirectory;
project.sourceSets.test.resources.srcDirs += task.outputDirectory;
// Turn project dependencies into task dependencies. We have to delay this until the end of the configuration
// phase because project dependencies are not fully known until then.
project.gradle.addBuildListener(new BuildAdapter() {
#Override
void projectsEvaluated(Gradle gradle) {
project.configurations.compile.each {
task.dependencyOutputs += it
}
}
});
}
}
CompileFoobarTask.groovy:
class CompileFoobarTask extends DefaultTask {
#InputDirectory
File sourceDirectory;
#InputFiles
List<File> dependencyOutputs = new ArrayList<>();
#OutputDirectory
File outputDirectory;
#TaskAction
void run() {
FileUtils.write(new File(outputDirectory, "timestamp"), "" + System.currentTimeMillis(), StandardCharsets.UTF_8);
}
}
build.gradle from project A:
apply plugin: 'java'
apply plugin: foobar.gradle.FoobarPlugin
repositories {
mavenCentral()
}
dependencies {
compile project(':b')
}
build.gradle from project B:
apply plugin: 'java'
apply plugin: foobar.gradle.FoobarPlugin
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.0'
}
Test runs and output:
martin#xyz:~/git-repos/gradle-test$ ./gradlew clean a:compileFoobar
adding dependency /home/martin/git-repos/gradle-test/b/build/libs/b.jar to task task ':a:compileFoobar'
> Task :a:compileFoobar
running task ':a:compileFoobar'
BUILD SUCCESSFUL in 1s
4 actionable tasks: 2 executed, 2 up-to-date
martin#xyz:~/git-repos/gradle-test$ ./gradlew clean b:compileFoobar
adding dependency /home/martin/git-repos/gradle-test/b/build/libs/b.jar to task task ':a:compileFoobar'
> Task :b:compileFoobar
running task ':b:compileFoobar'
BUILD SUCCESSFUL in 469ms
4 actionable tasks: 2 executed, 2 up-to-date
martin#xyz:~/git-repos/gradle-test$ ./gradlew clean a:compileJava
adding dependency /home/martin/git-repos/gradle-test/b/build/libs/b.jar to task task ':a:compileFoobar'
> Task :a:compileFoobar
running task ':a:compileFoobar'
> Task :b:compileFoobar
running task ':b:compileFoobar'
BUILD SUCCESSFUL in 487ms
7 actionable tasks: 5 executed, 2 up-to-date
martin#xyz:~/git-repos/gradle-test$ ./gradlew clean b:compileJava
adding dependency /home/martin/git-repos/gradle-test/b/build/libs/b.jar to task task ':a:compileFoobar'
> Task :b:compileFoobar
running task ':b:compileFoobar'
BUILD SUCCESSFUL in 471ms
4 actionable tasks: 3 executed, 1 up-to-date
As you can see, even though I add b.jar as a dependency to a:compileFoobar, Gradle won't build that JAR before running a:compileFoobar. The Java plugin seems to do something different because running a:compileJava WILL build b.jar first. What do I have to do to achieve the same for my task?
What you need to do is to explicitly create a Task dependency between consumer project's compileFoobar task and the producer project's jar task (in your example where project a depends on project b, you need to create task dependency a:compileFoobar -> b.jar)
You can achieve this in your custom plugin, by checking if the current project has dependencies of type ProjectDependency: if so you create the task dependency accordingly.
Code sample (in your plugin apply() method):
// Turn project dependencies into task dependencies. We have to delay this until the end of the configuration
// phase because project dependencies are not fully known until then.
project.gradle.addBuildListener(new BuildAdapter() {
#Override
void projectsEvaluated(Gradle gradle) {
project.configurations.each { config ->
config.dependencies.each { dep ->
if (dep instanceof ProjectDependency) {
def producerProject = ((ProjectDependency) dep).dependencyProject
def producerJarTask = producerProject.tasks.jar
println " **** Project $project.name depends on $producerProject.name"
println " => create dependency between $task to $producerJarTask"
task.dependsOn(producerJarTask)
}
}
}
}
})
Build execution:
$ ./gradlew clean a:compileFoobar
**** Project a depends on b
=> create dependency between task ':a:compileFoobar' to task ':b:jar'
> Task :a:clean
> Task :b:clean
> Task :b:compileFoobar
> Task :b:compileJava NO-SOURCE
> Task :b:processResources NO-SOURCE
> Task :b:classes UP-TO-DATE
> Task :b:jar
> Task :a:compileFoobar

No value has been specified for property 'mainClassName' in shadowJar

I am compile flink using gradle(v6.0.1) build tool like this, but show this error:
~ ⌚ 13:53:42
$ bash -c "$(curl https://flink.apache.org/q/gradle-quickstart.sh)" -- 1.10.0 2.11
~/quickstart ⌚ 14:08:22
$ ./gradlew clean shadowJar
> Task :shadowJar FAILED
FAILURE: Build failed with an exception.
* What went wrong:
A problem was found with the configuration of task ':shadowJar' (type 'ShadowJar').
> No value has been specified for property 'mainClassName'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
4 actionable tasks: 4 executed
this this my gradle build.gradle:
buildscript {
repositories {
jcenter() // this applies only to the Gradle 'Shadow' plugin
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id 'java'
id 'application'
// shadow plugin to produce fat JARs
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
apply plugin: 'application'
// artifact properties
group = 'org.myorg.quickstart'
version = '0.1-SNAPSHOT'
mainClassName = 'org.myorg.quickstart.StreamingJob'
description = """Flink Quickstart Job"""
ext {
javaVersion = '1.8'
flinkVersion = '1.10.0'
scalaBinaryVersion = '2.11'
slf4jVersion = '1.7.7'
log4jVersion = '1.2.17'
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
applicationDefaultJvmArgs = ["-Dlog4j.configuration=log4j.properties"]
// declare where to find the dependencies of your project
repositories {
mavenCentral()
}
// NOTE: We cannot use "compileOnly" or "shadow" configurations since then we could not run code
// in the IDE or with "gradle run". We also cannot exclude transitive dependencies from the
// shadowJar yet (see https://github.com/johnrengelman/shadow/issues/159).
// -> Explicitly define the // libraries we want to be included in the "flinkShadowJar" configuration!
configurations {
flinkShadowJar // dependencies which go into the shadowJar
// always exclude these (also from transitive dependencies) since they are provided by Flink
flinkShadowJar.exclude group: 'org.apache.flink', module: 'force-shading'
flinkShadowJar.exclude group: 'com.google.code.findbugs', module: 'jsr305'
flinkShadowJar.exclude group: 'org.slf4j'
flinkShadowJar.exclude group: 'log4j'
}
// declare the dependencies for your production and test code
dependencies {
// --------------------------------------------------------------
// Compile-time dependencies that should NOT be part of the
// shadow jar and are provided in the lib folder of Flink
// --------------------------------------------------------------
compile "org.apache.flink:flink-java:${flinkVersion}"
compile "org.apache.flink:flink-streaming-java_${scalaBinaryVersion}:${flinkVersion}"
// --------------------------------------------------------------
// Dependencies that should be part of the shadow jar, e.g.
// connectors. These must be in the flinkShadowJar configuration!
// --------------------------------------------------------------
//flinkShadowJar "org.apache.flink:flink-connector-kafka-0.11_${scalaBinaryVersion}:${flinkVersion}"
compile "log4j:log4j:${log4jVersion}"
compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"
// Add test dependencies here.
// testCompile "junit:junit:4.12"
}
// make compileOnly dependencies available for tests:
sourceSets {
main.compileClasspath += configurations.flinkShadowJar
main.runtimeClasspath += configurations.flinkShadowJar
test.compileClasspath += configurations.flinkShadowJar
test.runtimeClasspath += configurations.flinkShadowJar
javadoc.classpath += configurations.flinkShadowJar
}
run.classpath = sourceSets.main.runtimeClasspath
jar {
manifest {
attributes 'Built-By': System.getProperty('user.name'),
'Build-Jdk': System.getProperty('java.version')
}
}
shadowJar {
configurations = [project.configurations.flinkShadowJar]
}
I am read the some answer to tell that the script do dot have mainClassName,but my config contains the mainClassName config,what should I do to fix this error? I am using macOS catalina.
downgrade the gradle to 4.0.1,it works.this is the gradle-wrapper.properties config:
#Mon Jan 06 13:52:34 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
this is the build command:
~/quickstart ⌚ 14:48:25
$ ./gradlew clean shadowJar
Downloading https://services.gradle.org/distributions/gradle-4.0.1-all.zip
........10%.........20%........30%.........40%........50%.........60%.........70%........80%.........90%........100%
Starting a Gradle Daemon (subsequent builds will be faster)
BUILD SUCCESSFUL in 1m 46s
4 actionable tasks: 4 executed
maybe help you.

how to import the ShadowJar plugin for Kotlin (Gradle) builds?

Build failed:
thufir#dur:~/NetBeansProjects/kotlin_dsl$
thufir#dur:~/NetBeansProjects/kotlin_dsl$ gradle clean run
> Configure project :
e: /home/thufir/NetBeansProjects/kotlin_dsl/build.gradle.kts:4:12: Unresolved reference: github
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'kotlin_dsl'.
> Could not open cache directory 74ykawxta6db3b2bfk9grjikp (/home/thufir/.gradle/caches/4.3.1/gradle-kotlin-dsl/74ykawxta6db3b2bfk9grjikp).
> Internal error: unable to compile script, see log for details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
thufir#dur:~/NetBeansProjects/kotlin_dsl$
problematic import statement:
thufir#dur:~/NetBeansProjects/kotlin_dsl$
thufir#dur:~/NetBeansProjects/kotlin_dsl$ cat build.gradle.kts
import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.*
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
application
kotlin("jvm") version "1.1.51"
}
application {
mainClassName = "samples.HelloWorldKt"
}
dependencies {
compile(kotlin("stdlib"))
}
repositories {
jcenter()
}
thufir#dur:~/NetBeansProjects/kotlin_dsl$
removing the import for Shadow as described gives a clean build and run. How is the Shadow plugin JAR made available for Kotlin to import?
Gradle itself, using the DSL, creates Shadow JAR's fine.
Coming at this from a different angle:
Kotlin meets Gradle: gradle.build.kt with ShadowJar
with a working build file.
Like so:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm") version "1.5.21"
id("com.github.johnrengelman.shadow") version "7.0.0"
}
group = "xxx.yyy"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
tasks.withType<ShadowJar> {
archiveFileName.set("app.jar")
}

Resources