Skip to content

Commit

Permalink
Merge pull request #763 from square/rick/build-logic-composite-wrapper
Browse files Browse the repository at this point in the history
Move the `:gradle-plugin` project into the main build
  • Loading branch information
RBusarow authored Nov 2, 2023
2 parents 7507b27 + e129a47 commit 0ee0ccb
Show file tree
Hide file tree
Showing 16 changed files with 125 additions and 147 deletions.
34 changes: 6 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ jobs :
check-latest : true

- name : Publish to Maven Local
run : ./gradlew clean publishToMavenLocal --no-build-cache --no-daemon --stacktrace --no-parallel && cd gradle-plugin && ./gradlew clean publishToMavenLocal --no-build-cache --no-daemon --stacktrace && cd ..
run : ./gradlew clean publishToMavenLocal --no-build-cache --no-daemon --stacktrace --no-parallel

publish-snapshot :
runs-on : ubuntu-latest
if : github.repository == 'square/anvil' && github.ref == 'refs/heads/main'
timeout-minutes : 25
needs :
- test-ubuntu
- build-gradle-plugin
- test-gradle-plugin
- gradle-wrapper-validation
- publish-maven-local

Expand All @@ -136,23 +136,20 @@ jobs :
check-latest : true

- name : Publish Snapshots 1.9
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace && cd ..
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}

# TODO: Remove when we drop Kotlin 1.8 support
- name : Publish Snapshots 1.8
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Doverride_kotlin=1.8.22 -PVERSION_NAME=2.4.9-1-8-SNAPSHOT && cd gradle-plugin && ./gradlew clean publish --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=1.8.22 -PVERSION_NAME=2.4.9-1-8-SNAPSHOT && cd ..
run : ./gradlew clean publish --no-build-cache --no-daemon --stacktrace --no-parallel -Doverride_kotlin=1.8.22 -PVERSION_NAME=2.4.9-1-8-SNAPSHOT
env :
ORG_GRADLE_PROJECT_mavenCentralUsername : ${{ secrets.SONATYPE_NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword : ${{ secrets.SONATYPE_NEXUS_PASSWORD }}

build-gradle-plugin :
test-gradle-plugin :
runs-on : ubuntu-latest
defaults :
run :
working-directory : gradle-plugin

timeout-minutes : 15

Expand All @@ -174,7 +171,7 @@ jobs :
check-latest : true

- name : Test Gradle Plugin
run : ./gradlew assemble test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_agp=${{ matrix.agp-version }}
run : ./gradlew :gradle-plugin:assemble :gradle-plugin:test --no-build-cache --no-daemon --stacktrace -Doverride_kotlin=${{ matrix.kotlin-version }} -Doverride_agp=${{ matrix.agp-version }}

- name : Upload Test Results
uses : actions/upload-artifact@v3
Expand All @@ -184,25 +181,6 @@ jobs :
name : test-results-gradle-plugin-${{ matrix.kotlin-version }}-${{ matrix.agp-version }}
path : ./**/build/reports/tests/

ktlint-gradle-plugin :
runs-on : ubuntu-latest
defaults :
run :
working-directory : gradle-plugin

timeout-minutes : 15

steps :
- uses : actions/checkout@v3
- uses : actions/setup-java@v3
with :
distribution : 'temurin'
java-version : '11'
check-latest : true

- name : KtLint Gradle Plugin
run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace

kapt-for-dagger-factories :
runs-on : ubuntu-latest
timeout-minutes : 25
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ out

# Ignore the generated project.
/benchmark/

# Since :gradle-plugin is in two builds, it has two build directories
/gradle-plugin/build-anvil/
/gradle-plugin/build-composite-wrapper/
19 changes: 6 additions & 13 deletions build-logic/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,14 @@ rootProject.name = "build-logic"

dependencyResolutionManagement {
versionCatalogs {
Map<String, String> overrides = new LinkedHashMap()
System.getProperties().forEach { key, value ->
String keyString = key.toString()
if (keyString.startsWith("override_")) {
overrides.put(keyString, value.toString())
}
}
libs {
from(files("../gradle/libs.versions.toml"))
for (Map.Entry<String, String> entry : overrides.entrySet()) {
String key = entry.getKey()
String value = entry.getValue()
String catalogKey = key.substring("override_".length())
println("Overriding $catalogKey with $value")
version(catalogKey, value)
System.properties.each { key, value ->
if (key.toString().startsWith("override_")) {
String catalogKey = key.substring("override_".length())
println "Overriding $catalogKey with $value"
version(catalogKey, value.toString())
}
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions build-logic/src/main/kotlin/com/squareup/anvil/RootPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.squareup.anvil

import com.rickbusarow.kgx.libsCatalog
import com.rickbusarow.kgx.pluginId
import com.squareup.anvil.benchmark.BenchmarkPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin

open class RootPlugin : Plugin<Project> {
override fun apply(target: Project) {
Expand All @@ -14,7 +15,7 @@ open class RootPlugin : Plugin<Project> {

open class LibraryPlugin : Plugin<Project> {
override fun apply(target: Project) {
target.plugins.apply(KotlinPlatformJvmPlugin::class.java)
target.plugins.apply(target.libsCatalog.pluginId("kotlin-jvm"))
target.plugins.apply(KtlintConventionPlugin::class.java)
}
}
23 changes: 8 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@ import org.gradle.api.internal.project.DefaultProject
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

buildscript {
dependencies {
classpath("com.squareup.anvil:gradle-plugin:${findProperty("VERSION_NAME")}",)
}
}

plugins {
alias(libs.plugins.agp.application) apply false
alias(libs.plugins.agp.library) apply false
Expand All @@ -20,6 +14,11 @@ plugins {
alias(libs.plugins.ktlint) apply false
alias(libs.plugins.mavenPublishBase) apply false
id 'com.squareup.anvil.root'
id 'com.squareup.anvil' apply false
}

allprojects {
version = property("VERSION_NAME")
}

boolean isCi = (System.getenv('CI') ?: 'false').toBoolean()
Expand Down Expand Up @@ -54,7 +53,8 @@ subprojects {

// Dynamically configure JVM targets because Dagger compiler always uses the java 11 @Generated
// annotation regardless of release target
boolean isIntegrationTestOrSample = project.path.startsWith(":integration-test") || project.path.startsWith(":sample")
boolean isIntegrationTestOrSample = project.path.startsWith(":integration-test") ||
project.path.startsWith(":sample")

pluginManager.withPlugin("java") {
// Use JDK 11 but target Java 8 for maximum compatibility.
Expand Down Expand Up @@ -88,7 +88,7 @@ subprojects {
&& project.name != "annotations-optional"
&& project.name != "scopes"
&& project.name != "dagger-factories-only"
if (optInExperimental) {
if (project.path != ':gradle-plugin' && optInExperimental) {
freeCompilerArgs.add("-opt-in=com.squareup.anvil.annotations.ExperimentalAnvilApi")
}
}
Expand Down Expand Up @@ -121,13 +121,6 @@ subprojects {
}
}

// For any publish task invoked in the main build, there's a corresponding task in the gradle-plugin
// included build. Gradle doesn't invoke those included build tasks when the main build's tasks are
// run, and that's annoying. This fixes that behavior.
tasks.withType(PublishToMavenRepository).configureEach { mainTask ->
mainTask.dependsOn(gradle.includedBuild("gradle-plugin").task(":${mainTask.name}"))
}

def getProperty(String name, String defaultValue) {
return project.hasProperty(name) ? project.getProperty(name) : defaultValue
}
9 changes: 9 additions & 0 deletions gradle-plugin-build-logic/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
id 'java-base'
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(11))
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,24 @@ pluginManagement {
includeBuild('../build-logic')
}

rootProject.name = "gradle-plugin-build-logic"

dependencyResolutionManagement {
versionCatalogs {
Map<String, String> overrides = new LinkedHashMap()
System.getProperties().forEach { key, value ->
String keyString = key.toString()
if (keyString.startsWith("override_")) {
overrides.put(keyString, value.toString())
}
}
libs {
for (Map.Entry<String, String> entry : overrides.entrySet()) {
String key = entry.getKey()
String value = entry.getValue()
String catalogKey = key.substring("override_".length())
println("Overriding $catalogKey with $value")
version(catalogKey, value)
from(files("../gradle/libs.versions.toml"))
System.properties.each { key, value ->
if (key.toString().startsWith("override_")) {
String catalogKey = key.substring("override_".length())
println "Overriding $catalogKey with $value"
version(catalogKey, value.toString())
}
}
}
}

repositories {
gradlePluginPortal()
google()
mavenCentral()
if (hasProperty("anvil.allowSnapshots")) {
Expand All @@ -40,4 +37,5 @@ dependencyResolutionManagement {
}
}

rootProject.name = "gradle-plugin"
include ':gradle-plugin'
project(':gradle-plugin').projectDir = new File('../gradle-plugin')
41 changes: 27 additions & 14 deletions gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,43 @@ plugins {
alias libs.plugins.gradlePublish
alias libs.plugins.buildconfig
id 'java-gradle-plugin'
id 'com.squareup.anvil.publish'
}

def pomName = 'Anvil Gradle Plugin'
def pomDescription = 'A Kotlin compiler plugin to make dependency injection with Dagger 2 ' +
'easier by automatically merging Dagger modules and component interfaces.'

// This module is part of two builds:
// 1. The main build, which publishes the plugin to the Gradle plugin portal.
// 2. The included build, which is used by the main build to test the plugin.
// Only the main build should publish the plugin.
if (rootProject.name == 'anvil') {
apply plugin: 'com.squareup.anvil.publish'

publish {
configurePom(
artifactId: 'gradle-plugin',
pomName: pomName,
pomDescription: pomDescription
)
}
layout.buildDirectory.set(file('build-anvil'))
} else {
layout.buildDirectory.set(file('build-composite-wrapper'))
}

buildConfig {
className('BuildProperties')
packageName('com.squareup.anvil.plugin')
useKotlinOutput { topLevelConstants = true }
useKotlinOutput {
internalVisibility = true
topLevelConstants = true
}

buildConfigField('String', 'GROUP', "\"$GROUP\"")
buildConfigField('String', 'VERSION', "\"$VERSION_NAME\"")
}

def pomName = 'Anvil Gradle Plugin'
def pomDescription = 'A Kotlin compiler plugin to make dependency injection with Dagger 2 ' +
'easier by automatically merging Dagger modules and component interfaces.'

publish {
configurePom(
artifactId: 'gradle-plugin',
pomName: pomName,
pomDescription: pomDescription
)
}

gradlePlugin {
website = project.findProperty('POM_URL') as String
vcsUrl = project.findProperty('POM_SCM_URL') as String
Expand Down
15 changes: 0 additions & 15 deletions gradle-plugin/copy_properties.gradle

This file was deleted.

1 change: 0 additions & 1 deletion gradle-plugin/gradle

This file was deleted.

1 change: 0 additions & 1 deletion gradle-plugin/gradlew

This file was deleted.

1 change: 0 additions & 1 deletion gradle-plugin/gradlew.bat

This file was deleted.

Loading

0 comments on commit 0ee0ccb

Please sign in to comment.