gradle - 在shadowJar中没有为属性 'mainClassName'指定值

标签 gradle apache-flink

我正在像这样使用gradle(v6.0.1)构建工具来编译flink,但是显示此错误:

~ ⌚ 13:53:42
$ bash -c "$(curl https://flink.apache.org/q/gradle-quickstart.sh)" -- 1.10.0 2.11
~/quickstart ⌚ 14:08:22
$ ./gradlew clean shadowJar
> Task :shadowJar FAILED

FAILURE: Build failed with an exception.

* What went wrong:
A problem was found with the configuration of task ':shadowJar' (type 'ShadowJar').
> No value has been specified for property 'mainClassName'.

* 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

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.0.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 1s
4 actionable tasks: 4 executed

这是我的gradle build.gradle:
buildscript {
    repositories {
        jcenter() // this applies only to the Gradle 'Shadow' plugin
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
    }
}

plugins {
    id 'java'
    id 'application'
    // shadow plugin to produce fat JARs
    id 'com.github.johnrengelman.shadow' version '2.0.4'
}

apply plugin: 'application'

// artifact properties
group = 'org.myorg.quickstart'
version = '0.1-SNAPSHOT'
mainClassName = 'org.myorg.quickstart.StreamingJob'
description = """Flink Quickstart Job"""

ext {
    javaVersion = '1.8'
    flinkVersion = '1.10.0'
    scalaBinaryVersion = '2.11'
    slf4jVersion = '1.7.7'
    log4jVersion = '1.2.17'
}


sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

applicationDefaultJvmArgs = ["-Dlog4j.configuration=log4j.properties"]


// declare where to find the dependencies of your project
repositories {
    mavenCentral()
}

// NOTE: We cannot use "compileOnly" or "shadow" configurations since then we could not run code
// in the IDE or with "gradle run". We also cannot exclude transitive dependencies from the
// shadowJar yet (see https://github.com/johnrengelman/shadow/issues/159).
// -> Explicitly define the // libraries we want to be included in the "flinkShadowJar" configuration!
configurations {
    flinkShadowJar // dependencies which go into the shadowJar

    // always exclude these (also from transitive dependencies) since they are provided by Flink
    flinkShadowJar.exclude group: 'org.apache.flink', module: 'force-shading'
    flinkShadowJar.exclude group: 'com.google.code.findbugs', module: 'jsr305'
    flinkShadowJar.exclude group: 'org.slf4j'
    flinkShadowJar.exclude group: 'log4j'
}

// declare the dependencies for your production and test code
dependencies {
    // --------------------------------------------------------------
    // Compile-time dependencies that should NOT be part of the
    // shadow jar and are provided in the lib folder of Flink
    // --------------------------------------------------------------
    compile "org.apache.flink:flink-java:${flinkVersion}"
    compile "org.apache.flink:flink-streaming-java_${scalaBinaryVersion}:${flinkVersion}"

    // --------------------------------------------------------------
    // Dependencies that should be part of the shadow jar, e.g.
    // connectors. These must be in the flinkShadowJar configuration!
    // --------------------------------------------------------------
    //flinkShadowJar "org.apache.flink:flink-connector-kafka-0.11_${scalaBinaryVersion}:${flinkVersion}"

    compile "log4j:log4j:${log4jVersion}"
    compile "org.slf4j:slf4j-log4j12:${slf4jVersion}"

    // Add test dependencies here.
    // testCompile "junit:junit:4.12"
}

// make compileOnly dependencies available for tests:
sourceSets {
    main.compileClasspath += configurations.flinkShadowJar
    main.runtimeClasspath += configurations.flinkShadowJar

    test.compileClasspath += configurations.flinkShadowJar
    test.runtimeClasspath += configurations.flinkShadowJar

    javadoc.classpath += configurations.flinkShadowJar
}

run.classpath = sourceSets.main.runtimeClasspath

jar {
    manifest {
        attributes 'Built-By': System.getProperty('user.name'),
                'Build-Jdk': System.getProperty('java.version')
    }
}

shadowJar {
    configurations = [project.configurations.flinkShadowJar]
}

我已阅读一些答案,以告诉脚本点是否具有mainClassName,但我的配置包含mainClassName配置,我该怎么办才能解决此错误?我正在使用macOS catalina。

最佳答案

将gradle降级到4.0.1,它可以工作。这是gradle-wrapper.properties配置:

#Mon Jan 06 13:52:34 CST 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

这是构建命令:
~/quickstart ⌚ 14:48:25
$ ./gradlew clean shadowJar
Downloading https://services.gradle.org/distributions/gradle-4.0.1-all.zip
........10%.........20%........30%.........40%........50%.........60%.........70%........80%.........90%........100%
Starting a Gradle Daemon (subsequent builds will be faster)

BUILD SUCCESSFUL in 1m 46s
4 actionable tasks: 4 executed

也许可以帮助您。

关于gradle - 在shadowJar中没有为属性 'mainClassName'指定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61038776/

相关文章:

digital-ocean - 在DCOS中安装Flink出错

spring-mvc - Gradle如何配置构建文件以从同一项目创建Spring Boot jar和Spring Web-MVC War

xml - float 操作按钮无法实例化/膨胀错误

android-studio - 如何动态生成 Java 源代码以在 Android Studio 中使用 Gradle 进行构建?

java - GWT 接口(interface)问题 : Breaking on exception: TypeError: Cannot read property 'getRestWrapper' of undefined

kubernetes - Flink-在Kubernetes上部署Flink应用程序的多个实例

java - 低延迟 Flink 流连接

gradle - 内部 API 构造函数 DefaultDomainObjectSet(Class<T>) 已被弃用。这计划在 Gradle 7.0 中删除

apache-flink - Hazelcast Jet 和 Apache Flink 有什么区别

java - 从kafka到redis的flink管道