微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 由于’fatJar任务’,Gradle构建失败,尽管代码在另一个项目中适用于我

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

FAILURE: Build Failed with an exception.

Where:
Build file ‘D:\dev\MarkPublished\build.gradle’ line: 40

What went wrong:
A problem occurred evaluating root project ‘markpublished’.
Could not find method Attributes() for arguments [{Implementation->Title=Gradle Jar File, Implementation-Version=1.0-Snapshot, Main-Class=path.classname}] on root project ‘myproject’.

这是我的(缩短的)’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.

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

解决方法:

尝试将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
}

属性必须为小写,如属性.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐