Skip to content

Commit

Permalink
Merge pull request #37 from StefMa/upgrade_plugins_deps
Browse files Browse the repository at this point in the history
Upgrade plugins deps
  • Loading branch information
StefMa authored Dec 21, 2018
2 parents 704b6ea + cf200d3 commit 8c6f4b8
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
command: |
cd subprojects/consumer
echo "sdk.dir=$HOME/android-sdk" >> local.properties
./gradlew build artifactoryPublish -PartifactoryUser=admin -PartifactoryKey=password --no-daemon
./gradlew build artifactoryPublish --init-script init.gradle.kts -PartifactoryUser=admin -PartifactoryKey=password --no-daemon
workflows:
version: 2
Expand Down
38 changes: 29 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import guru.stefma.bintrayrelease.PublishExtension

plugins {
`java-gradle-plugin`
kotlin("jvm") version "1.2.60"
kotlin("jvm") version "1.3.11"
id("java-library")
id("guru.stefma.bintrayrelease") version "1.0.0" apply false
}
Expand All @@ -26,16 +26,36 @@ repositories {
jcenter()
}

val optionalPlugins by configurations.creating {
configurations["compileOnly"].extendsFrom(this)
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.7.5")
implementation("guru.stefma.androidartifacts:androidartifacts:1.1.1")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.2.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.2.0")
testImplementation("org.assertj:assertj-core:3.10.0")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0-RC1")
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1")
implementation("guru.stefma.androidartifacts:androidartifacts:1.3.0")

optionalPlugins("com.android.tools.build:gradle:3.1.4")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.2")
testImplementation("org.junit.jupiter:junit-jupiter-params:5.3.2")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.3.2")
testImplementation("org.assertj:assertj-core:3.11.1")
testImplementation("com.nhaarman.mockitokotlin2:mockito-kotlin:2.0.0")
}

// This will add the android tools into the "test classpath"
tasks.withType<PluginUnderTestMetadata> {
pluginClasspath.from(optionalPlugins)

// We have to remove guava-18 here because
// jfrog.buildinfo brings it as transitive dependecy
// the AGP uses guava-22.
// Unfourtaly Gradle picks 18 at test time
// which leads to a crash
// See also https://discuss.gradle.org/t/manage-transitive-dependencies-with-testkit/29949
val classpathWithoutGuava18 = pluginClasspath.files.filter { !it.path.contains("guava-18.0") }
pluginClasspath.setFrom(classpathWithoutGuava18)
}

group = "guru.stefma.artifactorypublish"
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS=""
DEFAULT_JVM_OPTS='"-Xmx64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
2 changes: 1 addition & 1 deletion gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS=
set DEFAULT_JVM_OPTS="-Xmx64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ pluginManagement {
}
}
}
}
}

rootProject.name = "artifactorypublish"
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package guru.stefma.artifactorypublish

import closureOf
import com.sun.xml.fastinfoset.util.StringArray
import org.gradle.api.Project
import org.jfrog.gradle.plugin.artifactory.dsl.ArtifactoryPluginConvention
import org.jfrog.gradle.plugin.artifactory.dsl.PublisherConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package guru.stefma.artifactorypublish

import guru.stefma.androidartifacts.AndroidArtifactsPlugin
import guru.stefma.androidartifacts.ArtifactsExtension
import guru.stefma.androidartifacts.JavaArtifactsPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.logging.LogLevel
import org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin

/**
Expand All @@ -16,24 +13,20 @@ class ArtifactoryPublishPlugin : Plugin<Project> {

override fun apply(project: Project) {
// Apply the artifactory plugin
project.plugins.apply(ArtifactoryPlugin::class.java)

when {
project.plugins.hasPlugin("com.android.library") -> {
// Apply the AndroidArtifactsPlugin on Android projects
project.plugins.apply(AndroidArtifactsPlugin::class.java)
}
project.plugins.hasPlugin("java-library") -> {
// ...and the JavaArtifactsPlugin on pure Java projects
project.plugins.apply(JavaArtifactsPlugin::class.java)
}
else -> {
project.logger.log(
LogLevel.INFO,
"You have to apply either the `com.android.library` plugin or the `java-library` plugin...")
return
}
project.pluginManager.apply(ArtifactoryPlugin::class.java)

// Apply the artifacts plugin
project.pluginManager.apply("guru.stefma.artifacts")

project.pluginManager.withPlugin("guru.stefma.androidartifacts") {
configurePlugin(project)
}
project.pluginManager.withPlugin("guru.stefma.javaartifacts") {
configurePlugin(project)
}
}

private fun configurePlugin(project: Project) {
val artifactsExtension = project.extensions.getByType(ArtifactsExtension::class.java)

// Create our own extension which can be setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun <T> Any.closureOf(action: T.() -> Unit): Closure<Any?> =
fun <T> Any.delegateClosureOf(action: T.() -> Unit) =
object : Closure<Unit>(this, this) {
@Suppress("unused") // to be called dynamically by Groovy
fun doCall() = uncheckedCast<T>(delegate).action()
fun doCall() = uncheckedCast<T>(delegate)!!.action()
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package guru.stefma.artifactorypublish

import guru.stefma.artifactorypublish.rule.ProjectSetupExtension
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.GradleRunner
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.CsvSource
Expand All @@ -15,28 +13,6 @@ class ArtifactoryPublishPluginTest(
private val androidProjectDir: File
) {

@Test
fun `apply plugin without android-library or java-library should log and do nothing`() {
// We override the build script here and just apply the plugin
val buildScript = File(javaProjectDir, "build.gradle")
buildScript.writeText(
"""
plugins {
id 'guru.stefma.artifactorypublish'
}
""")

val build = GradleRunner.create()
.withProjectDir(javaProjectDir)
.withPluginClasspath()
.withArguments("help", "--info")
.build()

assertThat(build.output).contains(
"You have to apply either the `com.android.library` plugin or the `java-library` plugin"
)
}

@ParameterizedTest(name = "GradleVersion {0} should be build/fail (1 = true; 0 = false): {1}")
@CsvSource(
value = [
Expand All @@ -46,7 +22,8 @@ class ArtifactoryPublishPluginTest(
"4.7, 1",
"4.8, 1",
"4.8.1, 1",
"4.9, 1"
"4.9, 1",
"4.10.3, 1"
]
)
fun `test publishArtifactory task in an java project with different gradle versions`(
Expand All @@ -70,7 +47,8 @@ class ArtifactoryPublishPluginTest(
"4.7, 1",
"4.8, 1",
"4.8.1, 1",
"4.9, 1"
"4.9, 1",
"4.10.3, 1"
]
)
fun `test publishArtifactory task in an android project with different gradle versions`(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,10 @@ class ProjectSetupExtension : BeforeAllCallback, AfterAllCallback, ParameterReso
val buildScript = File(androidProjectDir, "build.gradle")
buildScript.writeText(
"""
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
}
}
plugins {
id 'com.android.library'
id 'guru.stefma.artifactorypublish' apply false
}
apply plugin: "com.android.library"
apply plugin: "guru.stefma.artifactorypublish"
android {
Expand Down
2 changes: 1 addition & 1 deletion subprojects/consumer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The instance will be then available at [http://localhost:8081/artifactory/](http
After you have successfully setup the Artifactory you can finally publish
the library project by running:
```
./gradlew build artifactoryPublish -PartifactoryUser=admin -PartifactoryKey=password
./gradlew build artifactoryPublish --init-script init.gradle.kts -PartifactoryUser=admin -PartifactoryKey=password
```

> **Note:** If you have already are installed Artifactory instance you have to use your user and your API-Key instead
Expand Down
2 changes: 1 addition & 1 deletion subprojects/consumer/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: guru.stefma.artifactorypublish.ArtifactoryPublishPlugin
apply plugin: 'guru.stefma.artifactorypublish'

android {
compileSdkVersion = 26
Expand Down
11 changes: 11 additions & 0 deletions subprojects/consumer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
buildscript {
repositories {
mavenLocal()
google()
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:3.1.4")
classpath("guru.stefma.artifactorypublish:artifactorypublish:$rootProject.version")
}
}
18 changes: 0 additions & 18 deletions subprojects/consumer/buildSrc/build.gradle

This file was deleted.

Binary file modified subprojects/consumer/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
28 changes: 28 additions & 0 deletions subprojects/consumer/init.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class ProjectListener : ProjectEvaluationListener {
var currentVersion = ""

override fun beforeEvaluate(project: Project) {
// This will publish the library to the local maven before
if (project == project.rootProject) {
project.exec {
workingDir("../..")
commandLine("./gradlew", "publishToMavenLocal")

// This get the current version o the plugin
// and set it to the rootProject as version
currentVersion = File("../../build.gradle.kts")
.readLines()
.find { it.contains("version =") }!!
.split("= ")[1]
.replace("\"", "")
project.rootProject.version = currentVersion
}
}
}

override fun afterEvaluate(project: Project, state: ProjectState) {
// do nothing
}
}

gradle.addProjectEvaluationListener(ProjectListener())
2 changes: 1 addition & 1 deletion subprojects/consumer/java/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apply plugin: 'java-library'
apply plugin: guru.stefma.artifactorypublish.ArtifactoryPublishPlugin
apply plugin: 'guru.stefma.artifactorypublish'

repositories {
jcenter()
Expand Down

0 comments on commit 8c6f4b8

Please sign in to comment.