1

I have a Kotlin project with JDA API which I need to deploy on Heroku environment. To achieve that I created a JAR task in my build.gradle file.

jar {
    baseName = 'discord-stats-bot'
    version =  'v1'
    manifest {
        attributes('Main-Class': 'com.vchernogorov.discordbot.BotKt')
    }
    from {
        configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

But I was unable to build this JAR file because of the following error.

16:02:03 vchernogorov $ ./gradlew jar
:kaptGenerateStubsKotlin UP-TO-DATE
:kaptKotlin UP-TO-DATE
:compileKotlin UP-TO-DATE
:compileJava UP-TO-DATE
:copyMainKotlinClasses UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:inspectClassesForKotlinIC UP-TO-DATE
:jar

FAILURE: Build failed with an exception.

* What went wrong:
Could not expand ZIP '/Users/vchernogorov/.gradle/caches/modules-2/files-2.1/club.minnced/opus-java/1.0.4/596995aaf2f5b5091c4d251fdc11fa62680cc59e/opus-java-1.0.4.pom'.
> archive is not a ZIP archive

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 6.784 secs

This library is a dependency in a JDA project. So I need help with configuring this jar task in order to correctly build my executable and deploy it to Heroku.

Edit: Here's my dependencies block in build.gradle.

dependencies {
    compile 'com.google.guava:guava:23.0'
    compile "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.16"
    compile "org.jsoup:jsoup:1.10.3"
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    compile "net.dv8tion:JDA:3.8.0_436"
    compile "khttp:khttp:0.1.0"
    compile 'com.google.code.gson:gson:2.8.1'
}
Opal
  • 81,889
  • 28
  • 189
  • 210
Praytic
  • 1,771
  • 4
  • 21
  • 41

1 Answers1

4

In maven there's a special artifact of type pom. It is also published and downloaded as a dependency. In jar's from is neither a directory nor a jar file, that's why processing fails. To solve it you need to exclude the *.pom before collecting, so:

from {
   configurations
      .compile
      .findAll { !it.name.endsWith('pom') }
      .collect { it.isDirectory() ? it : zipTree(it) }
}  

Next time you can use gradle shadow plugin or similar - a plugin that builds uber jar, since it probably handles it correctly.

Opal
  • 81,889
  • 28
  • 189
  • 210