xref: /aosp_15_r20/external/nullaway/jar-infer/jar-infer-cli/build.gradle (revision f50c306653bc89b8210ce6c9e0b0b44fc134bc03)
1plugins {
2    id "java-library"
3    id "com.vanniktech.maven.publish"
4    id "com.github.johnrengelman.shadow"
5}
6
7// JarInfer requires JDK 11+, due to its dependence on WALA
8tasks.withType(JavaCompile) {
9    java.sourceCompatibility = JavaVersion.VERSION_11
10    java.targetCompatibility = JavaVersion.VERSION_11
11}
12
13repositories {
14    mavenCentral()
15}
16
17dependencies {
18    implementation deps.build.commonscli
19    implementation deps.build.guava
20    implementation project(":jar-infer:jar-infer-lib")
21
22    testImplementation deps.test.junit4
23    testImplementation(deps.build.errorProneTestHelpers) {
24        exclude group: "junit", module: "junit"
25    }
26}
27
28java {
29    withJavadocJar()
30    withSourcesJar()
31}
32
33jar {
34    manifest {
35        attributes('Main-Class': 'com.uber.nullaway.jarinfer.JarInfer')
36    }
37    // add this classifier so that the output file for the jar task differs from
38    // the output file for the shadowJar task (otherwise they overwrite each other's
39    // outputs, forcing the tasks to always re-run)
40    archiveClassifier = "nonshadow"
41}
42
43shadowJar {
44    mergeServiceFiles()
45    configurations = [
46        project.configurations.runtimeClasspath
47    ]
48    archiveClassifier = ""
49}
50shadowJar.dependsOn jar
51assemble.dependsOn shadowJar
52
53
54// We disable the default maven publications to make sure only
55// our custom shadow publication is used. Since we use the empty
56// classifier for our fat jar, it would otherwise clash with the
57// default maven publication (Also, this seems to be the only way
58// to get a pom.xml with no dependencies for our fat jar, as using
59// a classifier would result on both fat and thin jar sharing the
60// same pom.xml. Instead, we skip publishing the thin jar
61// altogether)
62tasks.withType(PublishToMavenRepository) {
63    onlyIf {
64        publication == publishing.publications.shadow
65    }
66}
67tasks.withType(PublishToMavenLocal) {
68    onlyIf {
69        publication == publishing.publications.shadow
70    }
71}
72
73publishing {
74    publications {
75        shadow(MavenPublication) { publication ->
76            project.shadow.component(publication)
77            // Since we are skipping the default maven publication, we append the `:sources` and
78            // `:javadoc` artifacts here. They are also required for Maven Central validation.
79            afterEvaluate {
80                artifact project.sourcesJar
81                artifact project.javadocJar
82            }
83            // The shadow publication does not auto-configure the pom.xml file for us, so we need to
84            // set it up manually. We use the opportunity to change the name and description from
85            // the generic NullAway values to ones specific for the JarInfer tool.
86            pom {
87                name = 'JarInfer'
88                description = 'A JVM bytecode null auto-annotation tool for use with NullAway'
89                url = project.property('POM_URL')
90                licenses {
91                    license {
92                        name = project.property('POM_LICENCE_NAME')
93                        url = project.property('POM_LICENCE_URL')
94                        distribution = project.property('POM_LICENCE_DIST')
95                    }
96                }
97                developers {
98                    developer {
99                        id = project.property('POM_DEVELOPER_ID')
100                        name = project.property('POM_DEVELOPER_NAME')
101                        url = project.property('POM_DEVELOPER_URL')
102                    }
103                }
104                scm {
105                    connection = project.property('POM_SCM_CONNECTION')
106                    developerConnection = project.property('POM_SCM_DEV_CONNECTION')
107                    url = project.property('POM_SCM_URL')
108                }
109            }
110        }
111    }
112
113    afterEvaluate {
114        // Below is a series of hacks needed to get publication to work with
115        // gradle-maven-publish-plugin >= 0.15.0 (itself needed after the upgrade to Gradle 8.0.2).
116        // Not sure why e.g. publishShadowPublicationToMavenCentralRepository must depend on signMavenPublication
117        // (rather than just signShadowPublication)
118        project.tasks.named('generateMetadataFileForMavenPublication').configure {
119            dependsOn 'sourcesJar'
120            dependsOn 'simpleJavadocJar'
121        }
122        if (project.tasks.findByName('signShadowPublication')) {
123            project.tasks.named('signShadowPublication').configure {
124                dependsOn 'sourcesJar'
125                dependsOn 'simpleJavadocJar'
126            }
127        }
128        project.tasks.named('publishShadowPublicationToMavenCentralRepository').configure {
129            if (project.tasks.findByName('signMavenPublication')) {
130                dependsOn 'signMavenPublication'
131            }
132        }
133        project.tasks.named('publishShadowPublicationToMavenLocal').configure {
134            dependsOn 'sourcesJar'
135            dependsOn 'simpleJavadocJar'
136            if (project.tasks.findByName('signMavenPublication')) {
137                dependsOn 'signMavenPublication'
138            }
139        }
140    }
141}
142