Java 由于';fatJar任务';虽然代码在另一个项目中为我工作
我试着用Gradle创建一个fatJar。我在另一个项目中找到了一个很好的例子。在我最近的项目中,“gradlew build”任务期间发生错误,即: 失败:生成失败,出现异常 其中: 生成文件'D:\dev\MarkPublished\Build.gradle'行:40 出了什么问题: 评估根项目“markpublished”时出现问题。 在根项目“myproject”上找不到参数[{Implementation->Title=Gradle Jar File,Implementation Version=1.0-Snapshot,Main Class=path.classname}]的方法属性() 这是我的(缩短的)“build.gradle”-文件:Java 由于';fatJar任务';虽然代码在另一个项目中为我工作,java,intellij-idea,gradle,build.gradle,gradlew,Java,Intellij Idea,Gradle,Build.gradle,Gradlew,我试着用Gradle创建一个fatJar。我在另一个项目中找到了一个很好的例子。在我最近的项目中,“gradlew build”任务期间发生错误,即: 失败:生成失败,出现异常 其中: 生成文件'D:\dev\MarkPublished\Build.gradle'行:40 出了什么问题: 评估根项目“markpublished”时出现问题。 在根项目“myproject”上找不到参数[{Implementation->Title=Gradle Jar File,Implementation Ve
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
}
属性必须为小写,如
属性
以创建spring引导jar工件:
1) 在build.gradle文件的最开始(第1行)插入以下代码:
2) jar名称由settings.gradle文件确定:
rootProject.name='commons-ex1111'
要在inteliJ中生成spring引导应用程序jar,在GRADLE窗口上触发'bootJar'任务,或者在命令行上简单地写'GRADLE bootJar'
Jar将在:\build\libs下创建
整个build.gradle文件:
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'
}
纠正了我的问题
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'
}