xref: /aosp_15_r20/external/jspecify/gradle/mrjar.gradle (revision 2167191df2fa07300797f1ac5b707370b5f38c48)
1*2167191dSAndroid Build Coastguard Worker/*
2*2167191dSAndroid Build Coastguard Worker * Copyright 2021 The JSpecify Authors.
3*2167191dSAndroid Build Coastguard Worker *
4*2167191dSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*2167191dSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*2167191dSAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*2167191dSAndroid Build Coastguard Worker *
8*2167191dSAndroid Build Coastguard Worker *     http://www.apache.org/licenses/LICENSE-2.0
9*2167191dSAndroid Build Coastguard Worker *
10*2167191dSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*2167191dSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*2167191dSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*2167191dSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*2167191dSAndroid Build Coastguard Worker * limitations under the License.
15*2167191dSAndroid Build Coastguard Worker */
16*2167191dSAndroid Build Coastguard Worker
17*2167191dSAndroid Build Coastguard Worker/**
18*2167191dSAndroid Build Coastguard Worker * This build configuration configures project to necessary files to support JEP 238: Multi-Release JAR Files.
19*2167191dSAndroid Build Coastguard Worker * https://openjdk.java.net/jeps/238
20*2167191dSAndroid Build Coastguard Worker *
21*2167191dSAndroid Build Coastguard Worker * It puts class files built for Java 9+ into META-INF/versions/9 directory.
22*2167191dSAndroid Build Coastguard Worker * It also create a manifest file with Multi-Release attribute.
23*2167191dSAndroid Build Coastguard Worker */
24*2167191dSAndroid Build Coastguard Worker
25*2167191dSAndroid Build Coastguard WorkersourceSets {
26*2167191dSAndroid Build Coastguard Worker    // The source set for classes stored in META-INF/versions/9 directory
27*2167191dSAndroid Build Coastguard Worker    java9 {
28*2167191dSAndroid Build Coastguard Worker        java {
29*2167191dSAndroid Build Coastguard Worker            srcDirs = [
30*2167191dSAndroid Build Coastguard Worker                'src/java9/java',
31*2167191dSAndroid Build Coastguard Worker                /*
32*2167191dSAndroid Build Coastguard Worker                 * We compile the main classes again: If we don't, then this
33*2167191dSAndroid Build Coastguard Worker                 * javac invocation contains only a module-info, so javac fails
34*2167191dSAndroid Build Coastguard Worker                 * because we're creating an empty module.
35*2167191dSAndroid Build Coastguard Worker                 *
36*2167191dSAndroid Build Coastguard Worker                 * But we won't include the main .class files when we place the
37*2167191dSAndroid Build Coastguard Worker                 * output module-info.class under META-INF/versions/9, thanks
38*2167191dSAndroid Build Coastguard Worker                 * to some more configuration below.
39*2167191dSAndroid Build Coastguard Worker                 */
40*2167191dSAndroid Build Coastguard Worker                'src/main/java'
41*2167191dSAndroid Build Coastguard Worker            ]
42*2167191dSAndroid Build Coastguard Worker        }
43*2167191dSAndroid Build Coastguard Worker    }
44*2167191dSAndroid Build Coastguard Worker}
45*2167191dSAndroid Build Coastguard Worker
46*2167191dSAndroid Build Coastguard Workertasks.named('compileJava9Java', JavaCompile).configure {
47*2167191dSAndroid Build Coastguard Worker    options.release = 9
48*2167191dSAndroid Build Coastguard Worker}
49*2167191dSAndroid Build Coastguard Worker
50*2167191dSAndroid Build Coastguard Workerjar {
51*2167191dSAndroid Build Coastguard Worker    into('META-INF/versions/9') {
52*2167191dSAndroid Build Coastguard Worker        from(sourceSets.java9.output) {
53*2167191dSAndroid Build Coastguard Worker            /*
54*2167191dSAndroid Build Coastguard Worker             * As discussed above, we compiled all the classes again. But all
55*2167191dSAndroid Build Coastguard Worker             * that we want to include under META-INF/versions/9 is the
56*2167191dSAndroid Build Coastguard Worker             * module-info.
57*2167191dSAndroid Build Coastguard Worker             */
58*2167191dSAndroid Build Coastguard Worker            include 'module-info.class'
59*2167191dSAndroid Build Coastguard Worker        }
60*2167191dSAndroid Build Coastguard Worker    }
61*2167191dSAndroid Build Coastguard Worker    manifest {
62*2167191dSAndroid Build Coastguard Worker        attributes 'Multi-Release': true
63*2167191dSAndroid Build Coastguard Worker    }
64*2167191dSAndroid Build Coastguard Worker}
65