首页 文章

感谢'fatJar task' Gradle构建失败,尽管代码在另一个项目中适用于我

提问于
浏览
4

我试着用Gradle创建一个fatJar . 我发现了一个很好的例子site在另一个项目中对我很有用 . 在我最近的项目中,'gradlew build'任务期间发生错误,即:

FAILURE:构建因异常而失败 . 其中:构建文件'D:\ dev \ MarkPublished \ build.gradle'行:40出了什么问题:评估根项目'markpublished'时出现问题 . 无法在根项目'myproject'上找到参数[{Implementation-> Title = Gradle Jar文件,Implementation-Version = 1.0-Snapshot,Main-Class = path.classname}]的方法Attributes() .

这是我的(缩短的)'build.gradle'文件:

plugins {
  id 'java'
  id 'idea'
}

group 'mygroup'
version '1.0-Snapshot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

idea {
    ...
}

task wrapper(type: Wrapper) {
    gradleVersion = '2.4'
}

repositories {
    ...
}

dependencies {
    ...
}

task fatJar(type: Jar) {
    manifest {
        Attributes ('Implementation-Title': 'Gradle Jar File',
                'Implementation-Version': version,
                'Main-Class': 'path.classname')
    }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with Jar
}

我使用Win7和IntelliJ Idea 14.1.5 .

老实说,我绝对没有任何线索,我不会在这里询问它是否在我的另一个项目中没有用 .

2 回答

  • 0

    尝试将fatJar任务设为:

    task fatJar(type: Jar) {
        manifest {
            attributes 'Implementation-Title': 'Gradle Jar File',
                       'Implementation-Version': version,
                       'Main-Class': 'path.classname'
        }
        from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
        with Jar
    }
    

    属性必须为小写,如 attributes .

  • 4

    要创建一个spring-boot jar工件:1)在build.gradle文件的最开头插入以下代码(第1行):

    buildscript {
     repositories {
        maven { url 'https://repo.spring.io/snapshot' }
        maven { url 'https://repo.spring.io/milestone' }
     }
     dependencies {
       classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE'
     }
    }
    

    2)jar名称由settings.gradle文件确定:rootProject.name ='commons-ex1111'

    要在inteliJ中生成spring-boot应用程序jar,请在GRADLE窗口上触发'bootJar'任务 . Jar将在:\ build \ libs下创建

    整个脚本:

    buildscript {
        repositories {
            maven { url 'https://repo.spring.io/snapshot' }
            maven { url 'https://repo.spring.io/milestone' }
        }
        dependencies {
          classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.1.2.RELEASE'
        }
    }
    
    plugins {
        id 'org.springframework.boot' version '2.1.3.RELEASE'
        id 'java'
        id "com.github.johnrengelman.shadow" version "1.2.3"
    }
    
    apply plugin: 'io.spring.dependency-management'
    
    group = 'ex1.example'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '1.8'
    
    repositories {
        mavenCentral()
    }
    
    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-actuator'
        implementation 'org.springframework.boot:spring-boot-starter-web'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    
    }
    

相关问题