我正在尝试为Java / Groovy混合项目生成一个工作罐。这是我的build.gradle文件:
plugins {
id 'groovy'
id 'java'
}
apply plugin: 'groovy'
group 'com.victor'
version '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.codehaus.groovy/groovy-all
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.5.7', ext: 'pom'
testCompile group: 'junit', name: 'junit', version: '4.12'
// jsoup HTML parser library @ https://jsoup.org/
compile 'org.jsoup:jsoup:1.12.1'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev493-1.23.0'
// https://mvnrepository.com/artifact/log4j/log4j
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile 'org.slf4j:slf4j-log4j12:1.7.18'
}
jar {
manifest {
attributes(
'Class-Path': configurations.compile.collect { it.getName() }.join(' '),
'Main-Class': 'com.victor.application.Application'
)
}
}
当我从命令行在项目的根文件夹中运行./gradlew build
时,出现以下错误消息:
失败:构建失败,并出现异常。
* What went wrong:
Failed to capture fingerprint of input files for task ':compileGroovy' property 'groovyClasspath' during up-to-date check.
> Cannot infer Groovy class path because no Groovy Jar was found on class path: [/home/victor/.gradle/caches/modules-2/files-2.1/org.codehaus.groovy/groovy-all/2.5.7/ce901dd2f4d0cc95123726ad0e9bd900e7a80b32/groovy-all-2.5.7.pom, /home/victor/.gradle/caches/modules-2/files-2.1/org.jsoup/jsoup/1.12.1/55819a28fc834c2f2bcf4dcdb278524dc3cf088f/jsoup-1.12.1.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.apis/google-api-services-sheets/v4-rev493-1.23.0/448b4779a44afbee9b068800730e1f8186eb83ad/google-api-services-sheets-v4-rev493-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.api-client/google-api-client/1.23.0/522ea860eb48dee71dfe2c61a1fd09663539f556/google-api-client-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.oauth-client/google-oauth-client-jetty/1.23.0/e0deaf34371e9ca09f9a04bcbaa854243283cae4/google-oauth-client-jetty-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-log4j12/1.7.18/1afd498e56689f56d2205d16a606e58db20698ac/slf4j-log4j12-1.7.18.jar, /home/victor/.gradle/caches/modules-2/files-2.1/log4j/log4j/1.2.17/5af35056b4d257e4b64b9e8069c0746e8b08629f/log4j-1.2.17.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.oauth-client/google-oauth-client-java6/1.23.0/7acbddf56c4ad04efc9d3b48fe015e6250241bf0/google-oauth-client-java6-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.oauth-client/google-oauth-client/1.23.0/e57ea1e2220bda5a2bd24ff17860212861f3c5cf/google-oauth-client-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.http-client/google-http-client-jackson2/1.23.0/fd6761f4046a8cb0455e6fa5f58e12b061e9826e/google-http-client-jackson2-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.guava/guava-jdk5/17.0/463f8378feba44df7ba7cd9272d01837dad62b36/guava-jdk5-17.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.mortbay.jetty/jetty/6.1.26/2f546e289fddd5b1fab1d4199fbb6e9ef43ee4b0/jetty-6.1.26.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-api/1.7.18/b631d286463ced7cc42ee2171fe3beaed2836823/slf4j-api-1.7.18.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.http-client/google-http-client/1.23.0/8e86c84ff3c98eca6423e97780325b299133d858/google-http-client-1.23.0.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.google.code.findbugs/jsr305/1.3.9/40719ea6961c0cb6afaeb6a921eaa1f6afd4cfdf/jsr305-1.3.9.jar, /home/victor/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.core/jackson-core/2.1.3/f6c3aed1cdfa21b5c1737c915186ea93a95a58bd/jackson-core-2.1.3.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.mortbay.jetty/jetty-util/6.1.26/e5642fe0399814e1687d55a3862aa5a3417226a9/jetty-util-6.1.26.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.mortbay.jetty/servlet-api/2.5-20081211/22bff70037e1e6fa7e6413149489552ee2064702/servlet-api-2.5-20081211.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient/4.0.1/1d7d28fa738bdbfe4fbd895d9486308999bdf440/httpclient-4.0.1.jar, /home/victor/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpcore/4.0.1/e813b8722c387b22e1adccf7914729db09bcb4a9/httpcore-4.0.1.jar, /home/victor/.gradle/caches/modules-2/files-2.1/commons-logging/commons-logging/1.1.1/5043bfebc3db072ed80fbd362e7caf00e885d8ae/commons-logging-1.1.1.jar, /home/victor/.gradle/caches/modules-2/files-2.1/commons-codec/commons-codec/1.3/fd32786786e2adb664d5ecc965da47629dca14ba/commons-codec-1.3.jar, /home/victor/Documentos/Programacion/Groovy/ScrapData/build/classes/java/main]
有人知道发生了什么吗?
答案 0 :(得分:1)
该错误看起来很奇怪,很遗憾,我无法重现该错误。
突出的一件事是常规依赖项上的ext: 'pom'
限定符。除非您真的知道自己在做什么,否则我会怀疑那可能不是您想要的。
话虽这么说,看来您正在尝试构建一个可执行jar,我认为一个有效的示例可能会帮助您解决问题。
以下修改后的build.gradle
文件:
plugins {
id 'groovy'
id 'java'
id 'com.github.johnrengelman.shadow' version '5.0.0'
}
apply plugin: 'groovy'
group 'com.victor'
version '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.5.7'
compile 'org.jsoup:jsoup:1.12.1'
compile 'com.google.api-client:google-api-client:1.23.0'
compile 'com.google.oauth-client:google-oauth-client-jetty:1.23.0'
compile 'com.google.apis:google-api-services-sheets:v4-rev493-1.23.0'
compile 'log4j:log4j:1.2.17'
compile 'org.slf4j:slf4j-log4j12:1.7.18'
testCompile 'junit:junit:4.12'
}
shadowJar {
baseName 'application'
manifest {
attributes 'Main-Class': 'com.victor.application.Application'
}
}
使用影子罐插件,该插件专门能够创建胖罐(包含您项目的所有依赖项的罐)。
具有上述构建文件和以下目录结构:
.
├── build.gradle
└── src
└── main
└── groovy
└── com
└── victor
└── application
└── Application.groovy
6 directories, 2 files
其中Application.groovy
包含以下代码:
package com.victor.application
class Application {
static void main(String[] args) {
println "Hello World!"
}
}
项目生成并产生以下输出:
~> gradle -v
------------------------------------------------------------
Gradle 5.4
------------------------------------------------------------
Build time: 2019-04-16 02:44:16 UTC
Revision: a4f3f91a30d4e36d82cc7592c4a0726df52aba0d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_191 (Oracle Corporation 25.191-b12)
OS: Mac OS X 10.14.4 x86_64
~> gradle shadowJar
BUILD SUCCESSFUL in 5s
2 actionable tasks: 2 executed
~> java -jar build/libs/application-1.0-all.jar
Hello World!
~>