无法为 gradle 项目创建 JAR 文件
Posted
技术标签:
【中文标题】无法为 gradle 项目创建 JAR 文件【英文标题】:Not able to create JAR file for gradle project 【发布时间】:2019-10-18 22:26:39 【问题描述】:我想创建一个可以上传到 AWS 上的 jar 文件,但每次我从命令提示符运行命令“gradle jar”时都会收到以下错误。
> Task :compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
每当我在命令提示符下运行“gradle clean”时,我都会得到“构建成功”。下面是build.gradle的内容:
buildscript
ext
springBootVersion = '2.0.4.RELEASE'
repositories
mavenCentral()
maven
url "https://plugins.gradle.org/m2/"
dependencies
classpath("org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion")
classpath "net.ltgt.gradle:gradle-apt-plugin:0.18"
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'net.ltgt.apt'
group = 'com.myproject.api'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8
ext
lombokVersion = '1.16.20'
mapstructVersion = '1.2.0.Final'
repositories
mavenCentral()
mavenLocal()
jcenter()
flatDir
dirs 'libs'
dependencies
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-mail')
compile('org.springframework.boot:spring-boot-starter-thymeleaf')
compile('org.springframework.data:spring-data-jpa')
compile('io.springfox:springfox-swagger2:2.9.2')
compile('io.springfox:springfox-swagger-ui:2.9.2')
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'org.json', name: 'json', version: '20180813'
compile files('libs/checksum_2.0.0.jar')
compileOnly("org.projectlombok:lombok:$lombokVersion")
compileOnly("org.mapstruct:mapstruct-jdk8:$mapstructVersion")
compileOnly("org.mapstruct:mapstruct-processor:$mapstructVersion")
runtime('org.springframework.boot:spring-boot-devtools')
runtime('mysql:mysql-connector-java')
testCompile('org.springframework.boot:spring-boot-starter-test')
eclipse
classpath
file.whenMerged cp ->
cp.entries.add( new org.gradle.plugins.ide.eclipse.model.SourceFolder('build/generated/source/apt/ma
in', null) )
我需要添加任何插件吗?提前致谢。请帮忙
【问题讨论】:
> Compilation failed; see the compiler error output for details.
尝试定位编译错误的来源并修复
@M.Ricciuti 我看到了错误的来源,它说:“解决项目'myproject-'的全局依赖管理不包括 [org.apache.tomcat:tomcat-annotations-api,ognl:ognl ] Excluding [] Caching disabled for task ':compileJava' because: Build cache is disabled Task ':compileJava' is not up-to-date because: Task has failed before. 对于增量任务,所有输入文件都被认为是过时的':compileJava'。需要完全重新编译,因为没有可用的增量更改信息。这通常是由干净的构建或更改编译器参数引起的"
问题不在于 gradle。问题在于您的 Java 代码。它不编译。阅读您从编译器获得的编译错误并修复它们。这就是编译失败的原因;有关详细信息,请参阅编译器错误输出。 表示。
@JBNizet 我是编程新手。你能帮我在spring工具套件中找到编译器错误输出窗口吗?
【参考方案1】:
我使用的是“gradle clean”和“gradle build”而不是“gradlew clean”和“gradlew build”。 gradlew 命令对我有用。
【讨论】:
【参考方案2】:打开任务管理器并强制停止Java(TM) Platform SE
二进制并删除
C:\Users\current user\.gradle\caches\jars-9\jars-9.lock file
【讨论】:
以上是关于无法为 gradle 项目创建 JAR 文件的主要内容,如果未能解决你的问题,请参考以下文章
从 Gradle 创建可执行 jar 文件并在 maven 中导入 jar
在 IntelliJ IDEA 中创建 Java Gradle 项目并构建 .jar 文件 - 如何?