gpt4 book ai didi

java - build/install/-shadow 目录——它是什么?

转载 作者:行者123 更新时间:2023-12-02 12:00:52 27 4
gpt4 key购买 nike

什么是build/install/gradleHelloWorld-shadow?该目录中应该包含什么内容,不应该包含什么内容?

最简单的“hello world”无法构建:

thufir@dur:~/NetBeansProjects/gradleHelloWorld$ 
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ gradle clean runShadow

> Task :shadowJar
A problem was found with the configuration of task ':shadowJar'. Registering invalid inputs and outputs via TaskInputs and TaskOutputs methods has been deprecated and is scheduled to be removed in Gradle 5.0.
- No value has been specified for property 'mainClassName'.
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.

> Task :startShadowScripts
Using TaskInputs.file() with something that doesn't resolve to a File object has been deprecated and is scheduled to be removed in Gradle 5.0. Use TaskInputs.files() instead.


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':installShadowDist'.
> The specified installation directory '/home/thufir/NetBeansProjects/gradleHelloWorld/build/install/gradleHelloWorld-shadow' is neither empty nor does it contain an installation for 'gradleHelloWorld'.
If you really want to install to this directory, delete it and run the install task again.
Alternatively, choose a different installation directory.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
5 actionable tasks: 5 executed

Publishing build scan...
https://gradle.com/s/t7jbmhjz23giw

thufir@dur:~/NetBeansProjects/gradleHelloWorld$

构建文件:

plugins {
id 'com.gradle.build-scan' version '1.8'
id 'java'
id 'application'
id 'com.github.johnrengelman.shadow' version '2.0.1'
}

buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
publishAlways()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

mainClassName = 'net.bounceme.dur.gradle.hello.App'

shadowJar {
baseName = 'greeter'
classifier = null
version = null
}

repositories {
jcenter()
}

configurations {
provided
}

dependencies {
}

中止后的项目runShadow:

thufir@dur:~/NetBeansProjects/gradleHelloWorld$ 
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ tree
.
├── build
│   ├── classes
│   │   └── java
│   │   └── main
│   │   └── net
│   │   └── bounceme
│   │   └── dur
│   │   └── gradle
│   │   └── hello
│   │   └── App.class
│   ├── install
│   │   └── gradleHelloWorld-shadow
│   ├── libs
│   │   └── greeter.jar
│   ├── scriptsShadow
│   │   ├── gradleHelloWorld
│   │   └── gradleHelloWorld.bat
│   └── tmp
│   ├── compileJava
│   └── shadowJar
│   └── MANIFEST.MF
├── build.gradle
├── gradle
│   └── wrapper
│   ├── gradle-wrapper.jar
│   └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│   └── java
│   ├── dur
│   └── net
│   └── bounceme
│   └── dur
│   └── gradle
│   └── hello
│   └── App.java
└── test
└── java

29 directories, 12 files
thufir@dur:~/NetBeansProjects/gradleHelloWorld$

有问题的 /home/thufir/NetBeansProjects/gradleHelloWorld/build/install/gradleHelloWorld-shadow 目录已被 clean 删除,确定 gradle 正在构建此目录。

刚刚升级的gradle:

thufir@dur:~$ 
thufir@dur:~$ sdk ls gradle
==== INTERNET NOT REACHABLE! ===================================================

Some functionality is disabled or only partially available.
If this persists, please enable the offline mode:

$ sdk offline

================================================================================

--------------------------------------------------------------------------------
Offline: only showing installed gradle versions
--------------------------------------------------------------------------------
> 4.3.1
* 4.2.1
--------------------------------------------------------------------------------
* - installed
> - currently in use
--------------------------------------------------------------------------------
thufir@dur:~$

(无线网络可能有点不稳定。)

最佳答案

你的问题我不清楚,据我所知,错误消息很清楚出了什么问题。

不确定您发布的解决方法是什么,我在评论中说要运行干净,因为大概这就是插件的要求,如果有兴趣,只需检查插件的源代码即可。

无论如何。

The Shadow plugin will also configure distribution tasks when in the presence of the application plugin. The plugin will create shadowDistZip and shadowDistTar which creates Zip and Tar distributions respectively. Each distribution will contain the shadowed JAR file along with the necessary start scripts to launch the application.

此外,该插件将创建 installShadowDist 和 startShadowScripts 任务,这些任务会暂存发行版构建/安装/-shadow/所需的文件。

另一件事是 mainClassName

Just like the normal jar task, when the application plugin is applied, the shadowJar manifest will be configured to contain the Main-Class attribute with the value specified in the project’s mainClassName attribute.

runShadow 是一个 javaExec 任务,可能需要配置?

runShadow {
// classpath = sourceSets.main.runtimeClasspath

main = 'net.bounceme.dur.gradle.hello.App'

// arguments to pass to the application
// args 'appArg1'
}

When applied along with the application plugin, the runShadow task will be created for starting the application from the shadowed JAR. The runShadow task is a JavaExec task that is configured to execute java -jar myproject-all.jar. It can be configured the same as any other JavaExec task.

ShadowJar Documentation

关于java - build/install/<project>-shadow 目录——它是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47261691/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com