Skip to content

Commit

Permalink
Add maven and gradle plugins for publishing (dropbox#5)
Browse files Browse the repository at this point in the history
* Add gradle plugin

* Add releasing notes

* Refactor sample app to allow for publishing the correct binaries

* Add maven publish plugin

* Add gradle portal plugin

* Remove unused dependency

* Add in detector from gradle portal plugin
  • Loading branch information
chris-mitchell authored Oct 29, 2020
1 parent b603ce9 commit 36f204b
Show file tree
Hide file tree
Showing 65 changed files with 551 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
.cxx
local.properties
buildSrc/build
buildSrc/.idea/
affected_module_detector.log
File renamed without changes.
84 changes: 84 additions & 0 deletions affectedmoduledetector/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
plugins {
id 'java-library'
id 'kotlin'
id 'java-gradle-plugin'
id 'maven-publish'
id "com.gradle.plugin-publish" version "0.12.0"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation("junit:junit:4.13.1")
testImplementation("com.nhaarman:mockito-kotlin:1.5.0")
testImplementation("com.google.truth:truth:1.0.1")
}

ext {
DESCRIPTION = "A Gradle Plugin and library to determine which modules were affected in a commit."
VERSION = "0.1.0-SNAPSHOT"
GIT_URL = 'https://github.com/Dropbox/AffectedModuleDetector'
GROUP_ID = "com.dropbox.affectedmoduledetector"
}

group = GROUP_ID
version = VERSION
description = DESCRIPTION

publishing {
publications {
maven(MavenPublication) {
pom {
name = 'Affected Module Detector'
description = 'A concise description of my library'
url = GIT_URL
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'mplat-dbx'
name = 'Dropbox'
}
}
scm {
connection = 'scm:git:git://github.com:dropbox/AffectedModuleDetector.git'
developerConnection = 'scm:git:ssh://github.com:dropbox/AffectedModuleDetector.git'
url = GIT_URL
}
}

from components.java
}
}
}

gradlePlugin {
plugins {
affectedModuleDetectorPlugin {
id = GROUP_ID
implementationClass = "com.dropbox.affectedmoduledetector.AffectedModuleDetectorPlugin"
}
}
}

pluginBundle {
website = GIT_URL
vcsUrl = GIT_URL
description = "A Gradle Plugin to determine which modules were affected in a commit."
tags = ["module", "git", "detector", "dependency"]

plugins {
affectedModuleDetectorPlugin {
// id is captured from java-gradle-plugin configuration
displayName = "Affected Module Detector"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
*/
@file:JvmName("AffectedModuleDetectorUtil")

package com.dropbox.detector

import com.dropbox.detector.AffectedModuleDetector.Companion.CHANGED_PROJECTS_ARG
import com.dropbox.detector.AffectedModuleDetector.Companion.DEPENDENT_PROJECTS_ARG
import com.dropbox.detector.AffectedModuleDetector.Companion.ENABLE_ARG
import com.dropbox.detector.AffectedModuleDetector.Companion.MODULES_ARG
package com.dropbox.affectedmoduledetector

import com.dropbox.affectedmoduledetector.AffectedModuleDetector.Companion.CHANGED_PROJECTS_ARG
import com.dropbox.affectedmoduledetector.AffectedModuleDetector.Companion.DEPENDENT_PROJECTS_ARG
import com.dropbox.affectedmoduledetector.AffectedModuleDetector.Companion.ENABLE_ARG
import com.dropbox.affectedmoduledetector.AffectedModuleDetector.Companion.MODULES_ARG
import com.dropbox.detector.GitClient
import com.dropbox.detector.GitClientImpl
import org.gradle.api.GradleException
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.invocation.Gradle
import org.gradle.api.logging.Logger
import java.io.File
import java.util.UUID

/**
* The subsets we allow the projects to be partitioned into.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) 2020, Dropbox, Inc. All rights reserved.
*/

package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/*
* Copyright (c) 2020, Dropbox, Inc. All rights reserved.
*/
package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import org.gradle.api.Project
import org.gradle.api.artifacts.ProjectDependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Copyright (c) 2020, Dropbox, Inc. All rights reserved.
*/

package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import org.gradle.api.Project
import org.gradle.api.logging.Logger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* Copyright (c) 2020, Dropbox, Inc. All rights reserved.
*/

package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import org.gradle.BuildAdapter
import org.gradle.BuildResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
implementation-class=com.dropbox.affectedmoduledetector.AffectedModuleDetectorPlugin
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import com.dropbox.detector.GitClient
import com.google.common.truth.Truth
import org.gradle.api.Project
import org.gradle.api.plugins.ExtraPropertiesExtension
import org.gradle.testfixtures.ProjectBuilder
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert
import org.junit.Assert.fail
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import java.io.File
import kotlin.test.fail

@RunWith(JUnit4::class)
class AffectedModuleDetectorImplTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import org.junit.rules.TestRule
import org.junit.runner.Description
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.dropbox.detector
package com.dropbox.affectedmoduledetector

import java.io.File
import junit.framework.TestCase.assertEquals
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ buildscript {
}

apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "com.dropbox.detector.AffectedModuleDetector"

allprojects {
repositories {
Expand Down

This file was deleted.

57 changes: 57 additions & 0 deletions releasing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Releasing

* Create a local release branch from `main`
```bash
git checkout main
git pull
git checkout -b release_0.1.0
```

* Update `version` in `buildSrc/build.gradle.kts` (remove `-SNAPSHOT`)
```kotlin
version = 0.1.0"
```
* Commit all local changes
```
git commit -am "Prepare 0.1.0 release"
```
* Create a tag and push it
```bash
git tag v0.1.0
git push origin v0.1.0
```
* Upload to Maven Central
```bash
./gradlew publishAllPublicationsToMavenRepository
```
* Upload to Gradle Plugin Portal
```bash
./gradlew login
./gradlew publishPlugins
```
* Merge the release branch to master
```
git checkout master
git pull
git merge --no-ff release_0.1.0
```
* Update `version` in `buildSrc/build.gradle.kts` (increase version and add `-SNAPSHOT`)
```kotlin
version = "REPLACE_WITH_NEXT_VERSION_NUMBER-SNAPSHOT"
```
* Commit your changes
```
git commit -am "Prepare for next development iteration"
```
* Push your changes
```
git push
```
19 changes: 18 additions & 1 deletion sample/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
/build
*.iml
.gradle
/local.properties
/.idea
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
buildSrc/build
buildSrc/.idea/
68 changes: 22 additions & 46 deletions sample/build.gradle
Original file line number Diff line number Diff line change
@@ -1,57 +1,33 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "com.dropbox.detector.sample"
minSdkVersion 23
targetSdkVersion 30
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
maven {
url "https://plugins.gradle.org/m2/"
}
mavenLocal()
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
dependencies {
classpath "com.android.tools.build:gradle:4.1.0"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath("org.jlleitschuh.gradle:ktlint-gradle:9.1.1")
}
}

affectedModuleDetector {
baseDir = "${project.rootDir}"
pathsAffectingAllModules = [
"buildSrc/"
]
apply plugin: "org.jlleitschuh.gradle.ktlint"
apply plugin: "com.dropbox.affectedmoduledetector"

logFolder = "${project.rootDir}"
allprojects {
repositories {
google()
jcenter()
}
}

dependencies {

implementation project(":sample-core")
implementation project(":sample-util")

implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
task clean(type: Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ plugins {
`java-gradle-plugin`
}


repositories {
google()
jcenter()
mavenLocal()
}

dependencies {
implementation("com.dropbox.affectedmoduledetector:affectedmoduledetector:0.1.0-SNAPSHOT")
testImplementation("junit:junit:4.13.1")
testImplementation("com.nhaarman:mockito-kotlin:1.5.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.4.10")
testImplementation("com.google.truth:truth:1.0.1")
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dropbox.test
package com.dropbox.sample

import com.dropbox.detector.AffectedModuleDetector
import com.dropbox.affectedmoduledetector.AffectedModuleDetector
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
Expand Down
Loading

0 comments on commit 36f204b

Please sign in to comment.