无法从Gradle应用程序创建胖罐

我很难用Gradle应用程序创建胖子。

我正在运行命令./gradlew jar./gradlew clean build。这两个命令似乎都在应用程序的各个子模块中创建了有效的.jars,但是项目根目录中的.jar仅包含MANIFEST.MF,没有其他内容。

应用程序的结构如下

  • nova-app;这是main方法所在的项目,也是Dropwizard的config.yml文件所在的项目
  • nova-dal
  • nova-core
  • build.gradle
  • Procfile
  • settings.gradle
  • ...其他不相关的文件/文件夹

build.gradle (在根项目中)

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URI

plugins {
    base
    kotlin("jvm") version "1.3.72"

    `maven-publish`

    // Apply the application plugin to add support for building a CLI application.
    java
    application
}

application {
    mainClassname = "com.nova.app.Nova"
}

tasks.withType<Jar> {
    enabled = true

    manifest {
        attributes["Main-Class"] = application.mainClassname
    }

    from(configurations.runtimeclasspath.get().map {if (it.isDirectory) it else zipTree(it)})
}

allprojects {
    group = "com.nova"
    version = "1.0.0"

    repositories {
        mavenCentral()
        maven { url = URI("https://plugins.gradle.org/m2/") }
    }

    tasks.withType<KotlinCompile>().configureEach {
        kotlinOptions.jvmTarget = "1.8"
        kotlinOptions.javaParameters = true
    }
}

tasks.register("stage") {
    dependsOn(":clean",":build")
}

subprojects {
    apply(plugin = "kotlin")
    apply(plugin = "jacoco")
    apply(plugin = "maven-publish")

    tasks.withType<Test>().configureEach {
        useJUnitPlatform()
    }

    dependencies {
       ...
    }

    configurations.all {
        resolutionStrategy.preferProjectModules()
    }

    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
}

build.gradle (在主类所在的nova-app项目中)

import org.springframework.boot.gradle.tasks.bundling.BootJar

plugins {
    id("org.springframework.boot") version "2.1.3.RELEASE"
}

tasks.withType<Jar> {
    enabled = true
}

tasks.withType<BootJar> {
    archiveFileName.set("${this.archiveBaseName.get()}.${this.archiveExtension.get()}")
}

dependencies {
    "implementation"(project(":nova-core"))
    "implementation"(project(":nova-dal"))
}

settings.gradle

rootProject.name = 'nova'

include ':nova-app'
include ':nova-core'
include ':nova-dal'

我希望能够使用java -jar build/libs/nova-1.0.0.jar之类的命令来运行该应用,但目前我正在使用Caused by: java.lang.ClassnotFoundException: com.nova.app.Nova

有人可以指出这个设置有什么问题吗?

iCMS 回答:无法从Gradle应用程序创建胖罐

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/1865914.html

大家都在问