首页 Flink项目构建模板 - Gradle
文章
取消

Flink项目构建模板 - Gradle

Flink项目构建模板 - Gradle

环境

  • Gradle:7.x
  • Java:8

相较于官方模板

  • 升级Gradle Shadow版本
  • 移出过时仓库JCenter
  • 修改过时语法
  • 仓库改为阿里镜像
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
buildscript {
    repositories {
        maven {
            // 源仓库地址:https://plugins.gradle.org/m2/
            url "https://maven.aliyun.com/repository/gradle-plugin"
        }
    }
    dependencies {
        classpath "gradle.plugin.com.github.johnrengelman:shadow:7.1.2"
    }
}


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

//group 'org.example'
version '1.0-SNAPSHOT'
mainClassName = 'org.myorg.quickstart.StreamingJob'

ext {
    javaVersion = '1.8'
    flinkVersion = '1.14.2'
    scalaBinaryVersion = '2.11'
    slf4jVersion = '1.7.32'
    log4jVersion = '2.17.1'
}

sourceCompatibility = javaVersion
targetCompatibility = javaVersion


repositories {
    maven {
        url 'https://maven.aliyun.com/repository/public'
    }
    mavenCentral()
}

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: 'org.apache.logging.log4j'
}

dependencies {
    // --------------------------------------------------------------
    // Compile-time dependencies that should NOT be part of the
    // shadow jar and are provided in the lib folder of Flink
    // --------------------------------------------------------------
    implementation "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:${flinkVersion}"

    implementation "org.apache.logging.log4j:log4j-api:${log4jVersion}"
    implementation "org.apache.logging.log4j:log4j-core:${log4jVersion}"
    implementation "org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}"
    implementation "org.slf4j:slf4j-log4j12:${slf4jVersion}"

}

// 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
}

test {
    useJUnitPlatform()
}

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

参考

本文由作者按照 CC BY 4.0 进行授权