Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin DSL support #317

Closed
crummy opened this issue Aug 16, 2017 · 8 comments
Closed

Kotlin DSL support #317

crummy opened this issue Aug 16, 2017 · 8 comments

Comments

@crummy
Copy link

crummy commented Aug 16, 2017

Shadow Version

2.0.0

Gradle Version

4.1

Expected Behavior

I should be able to run ./gradlew shadowJar with a build.gradle.kts file

Actual Behavior

Task 'shadowJar' not found in root project 'hello-world'.

Gradle Build Script(s)


import org.gradle.api.JavaVersion
import org.gradle.kotlin.dsl.*


buildscript {
    repositories {
        maven {
            setUrl("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("com.github.jengelman.gradle.plugins:shadow:2.0.0")
    }
}

plugins {
    application
}

application {
    mainClassName = "samples.HelloWorld"
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
    testCompile("junit:junit:4.12")
}

repositories {
    jcenter()
}
@thiagogcm
Copy link

try this

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
...

tasks {
    "shadowJar"(ShadowJar::class) {
        baseName = project.name
        classifier = null
        version = null
    }
...
}

@crummy
Copy link
Author

crummy commented Aug 17, 2017

That succeeded without any errors, but it doesn't seem to be picking up my main class: no main manifest attribute...

@crummy
Copy link
Author

crummy commented Aug 17, 2017

Additionally, the shadow jar seems to be empty. I changed your suggestion to this so I could separate the jars:

tasks {
    "shadowJar"(ShadowJar::class) {
        baseName = project.name + "-all"
        classifier = null
        version = null
    }
}

But here's the result:

 ~/code/kotlin-dsl/samples/hello-world   master ●  ./gradlew build shadowJar
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 11s
8 actionable tasks: 7 executed, 1 up-to-date
 ~/code/kotlin-dsl/samples/hello-world   master ●  jar -tvf build/libs/hello-world.jar
     0 Thu Aug 17 17:01:40 CEST 2017 META-INF/
    25 Thu Aug 17 09:24:34 CEST 2017 META-INF/MANIFEST.MF
     0 Thu Aug 17 09:24:34 CEST 2017 samples/
   637 Thu Aug 17 09:24:34 CEST 2017 samples/HelloWorld.class
 ~/code/kotlin-dsl/samples/hello-world   master ●  jar -tvf build/libs/hello-world-all.jar
     0 Thu Aug 17 17:01:42 CEST 2017 META-INF/
    25 Thu Aug 17 17:01:42 CEST 2017 META-INF/MANIFEST.MF

@mikroskeem
Copy link

Any update on this?

@johnrengelman
Copy link
Owner

@crummy you didn't actually apply the shadow plugin in your example build file. You've added teh jar to the classpath, but you haven't applied the plugin.

The example that @thiagogcm gives doesn't work because it's just creating a standalone ShadowJar task that isn't autoconfigured.

@THUFIR
Copy link

THUFIR commented Feb 7, 2018

Perhaps there's a preliminary step before:

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

as here:

https://stackoverflow.com/q/48659849/262852

@mikaelhg
Copy link

Since I originally came to this issue page looking for a solution for customizing ShadowJar tasks in Kotlin, I'd better leave the answer I came up with:

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
    kotlin("jvm") version "1.2.51"
    id("com.github.johnrengelman.shadow") version "2.0.4"
    application
}

group = "io.mikael"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation("io.pebbletemplates:pebble:3.0.0")
    implementation("com.atlassian.commonmark:commonmark:0.11.0")
    implementation("org.yaml:snakeyaml:1.21")
    implementation("org.slf4j:slf4j-nop:1.7.25")
}

tasks.withType<KotlinCompile> {
    kotlinOptions.jvmTarget = "1.8"
}

application {
    mainClassName = "io.mikael.static.AppKt"
}

tasks.withType<ShadowJar> {
    baseName = "app"
    classifier = ""
    version = ""
}

@bk-mz
Copy link

bk-mz commented Nov 19, 2019

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

tasks {
    named<ShadowJar>("shadowJar") {
        archiveBaseName.set("app")
        mergeServiceFiles()
        manifest {
            attributes(mapOf("Main-Class" to "com.app.App"))
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants