0

I try to build a working jar from my project by IntellIJ. (I add the artifact and build it from the build menu) I literally can build it as a clean helloworld but as I keep adding the dependencies it breaks. The built artifact those not find my main class: Error: Could not find or load main class hu.qlmdc.drp.HelloWorldKt After a lot of tests I found the exact dependency causing the problem: "com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8" Without it the project works but I need the dependency.

What causes this? How can I repair the artifact? My gradle file:


plugins {
    id "application"
    id "java"
    id "war"
    id "org.jetbrains.kotlin.jvm" version "1.5.0"
}

group 'hu.qlmdc.drp'
version '1.0-SNAPSHOT'

repositories {
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
    maven { url 'http://repo.jenkins-ci.org/releases/' }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib"
    implementation group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.5.0'
    implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.5.0', ext: 'pom'

    implementation "io.ktor:ktor-server-core:1.5.4"
    implementation "io.ktor:ktor-server-netty:1.5.4"
    implementation "io.ktor:ktor-metrics:1.5.4"
    implementation "io.ktor:ktor-locations:1.5.4"
    implementation "io.ktor:ktor-gson:1.5.4"
    implementation "io.ktor:ktor-client-core:1.5.4"
    implementation "io.ktor:ktor-client-apache:1.5.4"

    implementation "ch.qos.logback:logback-classic:1.2.3"

    //implementation 'mysql:mysql-connector-java:8.0.23'
    implementation "com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8"
    implementation "org.hibernate:hibernate-core:5.4.31.Final"

    implementation "org.apache.httpcomponents:httpclient:4.5.13"
    implementation "org.apache.httpcomponents:fluent-hc:4.5.13"

// Jenkins plugins
    implementation group: 'org.jenkins-ci.plugins', name: 'credentials', version: '2.3.15', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins', name: 'matrix-auth', version: '2.6.6', ext: 'jar'
    implementation group: 'org.jenkins-ci.plugins.workflow', name: 'workflow-cps', version: '2.90', ext: 'jar'


implementation fileTree(dir: 'lib', include: ['*.jar'])


}
  • Where did you define the main class? The Gradle `application` plugin that you apply requires to define a main class property: https://docs.gradle.org/current/userguide/application_plugin.html – Joffrey May 20 '21 at 16:53
  • See https://stackoverflow.com/a/45169655/104891. – CrazyCoder May 20 '21 at 18:08
  • @Joffrey The main class is configured in the META-INF/Manifest.FM file. If this would be the problem, the jar would not work without the dependency. Also I build with IntellIJ. I use gradle only for the dependencies. – hollo1996 May 21 '21 at 19:36
  • @CrazyCoder I do not see how this is connected to my problem. I will try do – hollo1996 May 21 '21 at 19:40
  • com.microsoft.sqlserver:mssql-jdbc:6.2.2.jre8 contains digital signature that gets copied to the fat jar which makes it impossible to run. – CrazyCoder May 21 '21 at 19:41

0 Answers0