| /* |
| * Copyright (C) 2016 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| /** |
| * This file was created using the `create_project.py` script located in the |
| * `<AndroidX root>/development/project-creator` directory. |
| * |
| * Please use that script when creating a new project, rather than copying an existing project and |
| * modifying its settings. |
| */ |
| |
| import androidx.build.BuildOnServerKt |
| import androidx.build.KotlinTarget |
| import androidx.build.LibraryType |
| import androidx.build.SdkHelperKt |
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile |
| |
| import java.util.regex.Matcher |
| import java.util.regex.Pattern |
| |
| plugins { |
| id("AndroidXPlugin") |
| id("AndroidXRepackagePlugin") |
| id("kotlin") |
| } |
| |
| repackage { |
| // Must match what is in room/room-external-antlr/build.gradle |
| addRelocation { |
| sourcePackage = "org.antlr" |
| targetPackage = "androidx.room.jarjarred.org.antlr" |
| } |
| // Must match what is in room/room-external-antlr/build.gradle |
| addRelocation { |
| sourcePackage = "org.stringtemplate" |
| targetPackage = "androidx.room.jarjarred.org.stringtemplate" |
| } |
| } |
| |
| androidx.configureAarAsJarForConfiguration("testImplementation") |
| |
| dependencies { |
| implementation(project(":room:room-common")) |
| implementation(project(":room:room-external-antlr")) |
| implementation(project(":room:room-migration")) |
| implementation(project(":room:room-compiler-processing")) |
| implementation(libs.kotlinStdlib) |
| implementation(libs.autoCommon) |
| implementation(libs.autoValueAnnotations) |
| implementation(libs.javapoet) |
| implementation(libs.kotlinPoet) |
| implementation(libs.kotlinPoetJavaPoet) |
| implementation(libs.kspApi) |
| // Must be compileOnly to not bring in antlr4 in runtime |
| // Repackaged antlr4 brought in by |
| // project(":room:room-external-antlr") and used at runtime |
| compileOnly(libs.antlr4) { |
| // antlr has dependencies on unrelated projects for its gui stuff, do not include them |
| exclude group: "org.abego.treelayout" |
| exclude group: "com.ibm.icu" |
| exclude group: "org.glassfish" |
| } |
| implementation(libs.sqliteJdbc) |
| implementation(libs.apacheCommonsCodec) |
| implementation(libs.intellijAnnotations) |
| testImplementation(libs.truth) |
| testImplementation(project(":kruth:kruth")) |
| testImplementation(libs.testParameterInjector) |
| testImplementation(libs.autoValue) // to access the processor in tests |
| testImplementation(libs.autoServiceAnnotations) |
| testImplementation(libs.autoService) // to access the processor in tests |
| testImplementation(project(":paging:paging-common")) |
| testImplementation(project(":room:room-compiler-processing-testing")) |
| testImplementation(libs.junit) |
| testImplementation(libs.jsr250) |
| testImplementation(libs.mockitoCore4) |
| testImplementation(libs.antlr4) |
| testImplementation(SdkHelperKt.getSdkDependency(project)) |
| testImplementationAarAsJar(project(":room:room-runtime")) |
| testImplementationAarAsJar(project(":sqlite:sqlite")) |
| testImplementation(project(":internal-testutils-common")) |
| } |
| |
| def generateAntlrTask = tasks.register("generateAntlrGrammar", GenerateAntlrGrammar) { task -> |
| def sourceFiles = [ |
| "SQLiteLexer.g4", |
| "SQLiteParser.g4" |
| ] |
| task.getSourceFiles().set(sourceFiles.collect { layout.projectDirectory.file(it) }) |
| task.getAntlrClasspath().from(configurations.compileClasspath) |
| task.getOutputDirectory().set(layout.buildDirectory.dir("generated/antlr/grammar-gen/")) |
| } |
| |
| sourceSets { |
| main.java.srcDirs += generateAntlrTask.map { it.outputDirectory } |
| } |
| |
| @CacheableTask |
| abstract class GenerateAntlrGrammar extends DefaultTask { |
| @PathSensitive(PathSensitivity.NONE) |
| @InputFiles |
| abstract ListProperty<RegularFile> getSourceFiles() |
| |
| @Classpath |
| abstract ConfigurableFileCollection getAntlrClasspath() |
| |
| @OutputDirectory |
| abstract DirectoryProperty getOutputDirectory() |
| |
| @Inject |
| abstract ExecOperations getExecOperations() |
| |
| @Inject |
| public GenerateAntlrGrammar() { |
| description = "Generates ANTLR Grammar used by Room" |
| group = "build" |
| } |
| |
| @TaskAction |
| void generateAntlrGrammar() { |
| File outputDirectoryFile = getOutputDirectory().asFile.get() |
| outputDirectoryFile.deleteDir() |
| execOperations.javaexec { |
| mainClass.set("org.antlr.v4.Tool") |
| classpath = getAntlrClasspath() |
| args( |
| *getSourceFiles().get().collect { it.getAsFile().absolutePath }, |
| "-visitor", |
| "-o", new File(outputDirectoryFile, "androidx/room/parser").path, |
| "-package", "androidx.room.parser" |
| ) |
| } |
| } |
| } |
| |
| /** |
| * This task validates the published artifacts of room compiler to ensure dependencies are properly |
| * specified. |
| */ |
| abstract class CheckArtifactTask extends DefaultTask { |
| @InputFiles |
| abstract ConfigurableFileCollection getArtifactInputs() |
| @InputFile |
| abstract RegularFileProperty getPomFile() |
| @OutputFile |
| abstract RegularFileProperty getResult() |
| |
| /** |
| * Checks the generated pom file to ensure it does not depend on any jarjarred dependencies |
| * but still depends on others. |
| */ |
| void validatePomTaskOutputs() { |
| File pom = getPomFile().asFile.get() |
| if (!pom.canRead()) { |
| throw new GradleException("Cannot find the pom file for room-compiler") |
| } |
| def pomContents = pom.newReader().text |
| Pattern antlrDep = Pattern.compile("<dependency>\\s.*antlr(.*\\s)*</dependency>") |
| Matcher matcher = antlrDep.matcher(pomContents) |
| if (matcher.find()) { |
| throw new GradleException("Room-compiler pom file should not depend on antlr.\n" + |
| "Pom Contents:\n $pomContents") |
| } |
| if(!pomContents.contains("<artifactId>kotlin-stdlib</artifactId>")) { |
| throw new GradleException("room-compiler should depend on kotlin stdlib.\n" + |
| "Pom Contents:\n $pomContents") |
| } |
| } |
| |
| @TaskAction |
| void validate() { |
| getResult().asFile.get().write("fail\n") |
| validatePomTaskOutputs() |
| // have a no-op output to make gradle happy w/ input/output checking. |
| getResult().asFile.get().write("ok\n") |
| } |
| } |
| |
| def checkArtifactContentsTask = tasks.register("checkArtifact", CheckArtifactTask) { task -> |
| task.getResult().set(layout.buildDirectory.file("checkArtifactOutput.txt")) |
| def pomTask = (TaskProvider<GenerateMavenPom>) project.tasks.named("generatePomFileForMavenPublication") |
| task.getPomFile().set( |
| project.objects.fileProperty().fileProvider( |
| pomTask.map { it.destination } |
| ) |
| ) |
| } |
| |
| afterEvaluate { |
| def publishTaskProvider = project.tasks.named("publishMavenPublicationToMavenRepository") |
| checkArtifactContentsTask.configure { checkArtifactTask -> |
| checkArtifactTask.getArtifactInputs().from { |
| publishTaskProvider.map { |
| ((PublishToMavenRepository) it).getPublication().artifacts.matching { |
| it.classifier == null |
| }.collect { |
| it.file |
| } |
| } |
| } |
| } |
| } |
| |
| // make sure we validate published artifacts on the build server. |
| BuildOnServerKt.addToBuildOnServer(project, checkArtifactContentsTask) |
| |
| tasks.withType(KotlinCompile).configureEach { |
| kotlinOptions { |
| freeCompilerArgs += [ |
| "-opt-in=kotlin.contracts.ExperimentalContracts", |
| "-opt-in=androidx.room.compiler.processing.ExperimentalProcessingApi", |
| "-opt-in=com.squareup.kotlinpoet.javapoet.KotlinPoetJavaPoetPreview" |
| ] |
| } |
| } |
| |
| tasks.withType(Test).configureEach { |
| it.systemProperty("androidx.room.compiler.processing.strict", "true") |
| it.maxParallelForks = 8 |
| if (project.providers.environmentVariable("GITHUB_ACTIONS").present) { |
| // limit memory usage to avoid running out of memory in the docker container. |
| it.maxHeapSize = "512m" |
| } |
| } |
| |
| androidx { |
| name = "Room Compiler" |
| type = LibraryType.ANNOTATION_PROCESSOR |
| inceptionYear = "2017" |
| description = "Android Room annotation processor" |
| kotlinTarget = KotlinTarget.KOTLIN_2_0 |
| } |