繁体   English   中英

带有依赖项的Jar Spring Boot Gradle

[英]Jar with dependencies spring boot gradle

我试图制作具有依赖项的jar,因为在通过java -Dspring.config.location=myProperties -jar myJar启动jar时遇到了NoClassDefFoundError ,经过大量搜索后,我发现可以使用以下解决方案来实现此目的罐子块:

from{
        configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
    }

一切都很好,除了构建jar的时间(大约1分钟),并根据以下答案: Gradle:使用Spring Boot Dependencies构建“胖jar”,我不需要创建其他任务,是对于bootRepackage来说已经足够了,但是我收到了我上面提到的关于bootRepackage的错误,我不明白为什么。

这是我的build.gradle的内容,我正在使用Spring Boot 1.5.15:

/*
 * This file was generated by the Gradle 'init' task.
 */
buildscript {
    ext.springBootVersion = '1.5.15.RELEASE'
    ext.managementVersion = '1.0.6.RELEASE'
    ext.axis2Version = '1.7.9'
    repositories {
        mavenCentral()
        mavenLocal()

    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        //classpath "io.spring.gradle:dependency-management-plugin:${managementVersion}"
        //classpath "com.intershop.gradle.wsdl:wsdl-gradle-plugin:2.0.1"
    }
}

plugins {
    id 'java'
    id 'maven'
    id 'org.springframework.boot' version '1.5.15.RELEASE'
    id 'io.spring.dependency-management' version '1.0.6.RELEASE'

} 

configurations{
    implementation{
        exclude group: 'javax.servlet', module: 'servlet-api'
    }
}

dependencies {

    implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
    implementation 'org.springframework.integration:spring-integration-mongodb'
    implementation 'org.springframework.integration:spring-integration-amqp'


    testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
    testImplementation 'org.mockito:mockito-core:2.6.1'

    implementation 'org.apache.ws.commons.axiom:axiom-jaxb:1.2.20'    

    implementation('org.apache.axis2:axis2-kernel:1.7.9'){
        exclude group: 'javax.servlet', module: 'servlet-api'
        //The exclude above don't work
    }

    implementation "org.apache.axis2:axis2-kernel:${axis2Version}"

    implementation "org.apache.axis2:axis2-wsdl2code-maven-plugin:${axis2Version}"
    implementation "org.apache.axis2:axis2-transport-http:${axis2Version}"


}

wsdl {
    axis2 {
        genNameAxis2 {
           //someAxis2Tasks
        }
    }
}

wsdl2java {

    //someWsdlTasks   
}

wsdl2javaExt {
    cxfVersion = "3.2.1"
}

jar {
    manifest{
        attributes ('Main-Class': 'dummy.Application')
    }

    from{
        configurations.runtimeClasspath.collect {it.isDirectory() ? it : zipTree(it)}
    }
    archiveBaseName = 'projectName'
    archiveVersion = '1.0.0'
}

bootRepackage{
    mainClass = 'dummy.Application'
    //classifier = 'boot' I'm getting an error with this argument
}

repositories {
    mavenLocal()    
}


group = 'dummy.group'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
targetCompatibility = '1.8'

先感谢您。

升级到Gradle 5并为依赖项使用“实现”而不是“编译”后,我遇到了同样的问题。

Gradle构建了一个没有子项目jar或依赖项(根本没有BOOT-INF / lib目录)的主jar。 在父项目中将“实现”更改回“编译”仅解决了该问题(没有其他更改)。

因此,显然,Spring Boot 1.5.9 Gradle插件不适用于新的实现配置。 请注意,Spring Boot 2和新的bootJar任务可以正常工作,这个问题仅与旧的bootRepackage和新的实现配置有关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM