теневой плагин в gradle не работает — сборка gradle не создает толстую банку

У меня есть следующий build.gradle контент:

group 'com.example'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
        maven { url "https://plugins.gradle.org/m2/" }
    }
    dependencies {
        classpath "com.github.jengelman.gradle.plugins:shadow:2.0.1"
    }
}


apply plugin: 'scala'   
apply plugin: "com.github.johnrengelman.shadow"
sourceCompatibility = java_version


repositories {
    mavenCentral()
}

dependencies {
    // my dependencies:
    compile group: 'org.apache.spark', name: "spark-sql_$scala_major", version: spark_version
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Проблема в том, что запуск gradle build не создает толстую банку.

Просмотр зависимостей задач при запуске gradle tasks --all показывает, что задача shadowJar существует, но задача build от нее не зависит:

:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

Build Setup tasks
-----------------
init - Initializes a new Gradle build.
wrapper - Generates Gradle wrapper files.

Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
scaladoc - Generates Scaladoc for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'scalaGradleHW'.
components - Displays the components produced by root project 'scalaGradleHW'. [incubating]
dependencies - Displays all dependencies declared in root project 'scalaGradleHW'.
dependencyInsight - Displays the insight into a specific dependency in root project 'scalaGradleHW'.
dependentComponents - Displays the dependent components of components in root project 'scalaGradleHW'. [incubating]
help - Displays a help message.
model - Displays the configuration model of root project 'scalaGradleHW'. [incubating]
projects - Displays the sub-projects of root project 'scalaGradleHW'.
properties - Displays the properties of root project 'scalaGradleHW'.
tasks - Displays the tasks runnable from root project 'scalaGradleHW'.

Shadow tasks
------------
knows - Do you know who knows?
shadowJar - Create a combined JAR of project and runtime dependencies

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Other tasks
-----------
compileJava - Compiles main Java source.
compileScala - Compiles the main Scala source.
compileTestJava - Compiles test Java source.
compileTestScala - Compiles the test Scala source.
processResources - Processes main resources.
processTestResources - Processes test resources.

person Joey Baruch    schedule 14.12.2017    source источник
comment
Используя плагин приложения apply plugin: 'application', неявно применяет Distribution plugin, что вызывает следующую цепочку зависимостей : build -> assemble -> shadowDistTar -> shadowJar. Таким образом, вызов gradle build генерирует ожидаемый fatJar   -  person Joey Baruch    schedule 17.12.2017
comment
большое спасибо, это сработало для меня   -  person Haranath Boggarapu    schedule 07.01.2021


Ответы (1)


Задачу сборки в Gradle часто ошибочно принимают за задачу, которая создает все задачи в проекте. . Задача «сборки» фактически предоставляется плагином java-base и включает в себя следующие задачи:

compileJava, processResources, classes, jar, assemble, compileTestJava, processTestResources, testClasses, test, and check

Вместо запуска «градуированной сборки» я рекомендую использовать defaultsTasks

`defaultTasks 'build', 'shadowJar'`

Помещение этой строки в ваш build.gradle позволит вызывать Gradle без аргументов, так что запускаются и build, и shadowJar.

> gradle

Я не знаком с плагином shadowJar, но если он предоставляет задачу с именем shadowJar, использование строки dependOn в build.gradle может упростить строку defaultTasks.

project.tasks.shadowJar.dependsOn build

упрощает строку defaultTasks до

defaultTasks 'shadowJar'
person Alan Effrig    schedule 14.12.2017