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