Каталог build / install /<project>-shadow - что это?
Что такое build/install/gradleHelloWorld-shadow
? Что должно или не должно быть в этом каталоге?
Простейший из возможных "Привет мир" не удается построить:
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:~$
(Wi-Fi может быть немного ненадежным.)
3 ответа
Ваша проблема мне неясна, насколько я вижу, ошибка msg совершенно ясно, что не так.
Не уверенный, какой обходной путь вы опубликовали, я сказал в комментарии, что он работает чисто, потому что, по-видимому, это то, что требует плагин, просто проверьте исходный код плагина, если интересно, почему.
Тем не мение.
Плагин Shadow также будет настраивать задачи распространения при наличии плагина приложения. Плагин создаст shadowDistZip и shadowDistTar, которые создают распределения Zip и Tar соответственно. Каждый дистрибутив будет содержать затененный JAR-файл вместе с необходимыми сценариями запуска для запуска приложения.
Кроме того, плагин создаст задачи installShadowDist и startShadowScripts, которые размещают необходимые файлы для дистрибутива для сборки / установки /-shadow/.
Другое дело, что mainClassName
Как и в случае обычной задачи jar, когда применяется плагин приложения, манифест shadowJar будет настроен так, чтобы он содержал атрибут Main-Class со значением, указанным в атрибуте mainClassName проекта.
runShadow
такое задача javaExec, вероятно, нуждается в настройке?
runShadow {
// classpath = sourceSets.main.runtimeClasspath
main = 'net.bounceme.dur.gradle.hello.App'
// arguments to pass to the application
// args 'appArg1'
}
При применении вместе с плагином приложения будет создана задача runShadow для запуска приложения из затененного JAR-файла. Задача runShadow - это задача JavaExec, настроенная для выполнения java -jar myproject-all.jar. Его можно настроить так же, как любую другую задачу JavaExec.
Работать вокруг:
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ gradle clean assembleShadowDist
> 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.
BUILD SUCCESSFUL in 0s
6 actionable tasks: 6 executed
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ cd build/libs/
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$ ll
total 20
drwxr-xr-x 2 thufir thufir 4096 Nov 13 02:53 ./
drwxr-xr-x 7 thufir thufir 4096 Nov 13 02:53 ../
-rw-r--r-- 1 thufir thufir 1492 Nov 13 02:53 greeter.jar
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$ jar xf greeter.jar
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$ ll
total 28
drwxr-xr-x 4 thufir thufir 4096 Nov 13 02:53 ./
drwxr-xr-x 7 thufir thufir 4096 Nov 13 02:53 ../
-rw-r--r-- 1 thufir thufir 1492 Nov 13 02:53 greeter.jar
drwxr-xr-x 2 thufir thufir 4096 Nov 13 02:53 META-INF/
drwxr-xr-x 3 thufir thufir 4096 Nov 13 02:53 net/
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$ cat META-INF/MANIFEST.MF
Manifest-Version: 1.0
Main-Class: net.bounceme.dur.gradle.hello.App
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$ java -jar greeter.jar
Nov 13, 2017 2:53:38 AM net.bounceme.dur.gradle.hello.App run
INFO: helloooo
thufir@dur:~/NetBeansProjects/gradleHelloWorld/build/libs$
- почему это работает?
- почему не
runShadow
Работа?
Лучшее решение, все еще обходной путь. Переключение обратно на gradle 4.2.1 с 4.3.1 работает:
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ sdk use gradle 4.3.1
Using gradle version 4.3.1 in this shell.
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
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ sdk use gradle 4.2.1
Using gradle version 4.2.1 in this shell.
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
thufir@dur:~/NetBeansProjects/gradleHelloWorld$ gradle clean runShadow
Starting a Gradle Daemon (subsequent builds will be faster)
> Task :shadowJar
The SimpleWorkResult type has been deprecated and is scheduled to be removed in Gradle 5.0. Please use WorkResults.didWork() instead.
> Task :runShadow
Nov 13, 2017 12:02:51 PM net.bounceme.dur.gradle.hello.App run
INFO: helloooo
BUILD SUCCESSFUL in 12s
6 actionable tasks: 6 executed
thufir@dur:~/NetBeansProjects/gradleHelloWorld$
Это ошибка?