Skip to content

Commit

Permalink
updated one of the demos to use the "plugin id" approach and now runs…
Browse files Browse the repository at this point in the history
… the demos as part of the build.
  • Loading branch information
Johnlon committed Jul 27, 2023
1 parent 1b7f8dc commit f71d936
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 18 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RELEASE NOTES

- 1.8

- Enabled use of the newer gradle "plugin id" syntax

- 1.7.0

- Upgrade to gradle 7
Expand Down
63 changes: 57 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
// .\gradlew clean build publishToSonatype closeAndReleaseSonatypeStagingRepository
// use publishToMavenLocal to install to the local repo for testing
// RELEASNG ...
// place gradle.properties dir in c:\users\johnl\gradlerelease\
// .\gradlew -g c:\users\johnl\gradlerelease clean build publishToSonatype closeAndReleaseSonatypeStagingRepository

// TESTING LOCALLY - to install to the local repo for testing
// .\gradlew publishToMavenLocal

// to see staged builds login and go to https://oss.sonatype.org/#stagingRepositories


plugins {
id("io.github.gradle-nexus.publish-plugin").version("1.0.0")
id 'java-library'
id 'java-gradle-plugin'
id 'groovy'
}

apply plugin: 'groovy'
apply plugin: 'maven-publish'
apply plugin: 'signing'

group 'com.portingle'
archivesBaseName = "classpath-hell"
version '1.7.0'
version '1.8'

repositories {
mavenCentral()
Expand Down Expand Up @@ -83,7 +88,40 @@ task createPluginClasspath {
}
}

task runDemoPass(type: Exec) {
dependsOn(["publishToMavenLocal"])

workingDir 'demo/shouldPass'
commandLine 'cmd', '/c', '..\\..\\gradlew', 'clean', 'build', '-i'
doFirst {
println("EXEC PASSING DEMO")
}
doLast {
println("\nEXEC END")
}
}
task runDemoFail(type: Exec) {
dependsOn(["publishToMavenLocal"])

workingDir 'demo/shouldFail'
commandLine 'cmd', '/c', '..\\..\\gradlew', 'clean', 'build', '-i'

ignoreExitValue true

doFirst {
println("EXEC FAILING DEMO")
}
doLast {
if(executionResult.get().exitValue == 0) {
System.err.println("\nEXEC END - DID NOT GET THE EXPECTED FAILURE!!!")
throw new GradleException("demo at '" + workingDir + "' should have failed but did not fail !!!!!!!")
}
println("\nEXEC END - WITH EXPECTED FAILURE OF SCAN")
}
}

test.dependsOn(['createPluginClasspath'])
test.finalizedBy(['runDemoPass','runDemoFail'])

// consider using the Gradle Nexus Staging Maven as this avoids need to use the NExus gui to close and release the stage artifact.
// if the sonatypeUsername is provided by the gradle properties then a release is enabled
Expand All @@ -101,8 +139,10 @@ if (project.properties.containsKey("sonatypeUsername")) {

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// Ues pluginMaven - https://github.com/gradle/gradle/issues/10384
// To address...
// Multiple publications with coordinates 'com.portingle:classpath-hell:1.8' are published to repository 'mavenLocal'. The publications will overwrite each other!
pluginMaven(MavenPublication) {

pom {
name = 'classpath-hell'
Expand Down Expand Up @@ -182,5 +222,16 @@ sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8


gradlePlugin {
// Define the plugin
plugins {
classpathHell {
id = 'com.portingle.classpath-hell'
implementationClass = 'classpathHell.ClasspathHellPlugin'
}
}
}




4 changes: 2 additions & 2 deletions demo/shouldFail/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
1. First do a `gradle install` of the main project to put the plugin jar into the local maven repo.
1. First do a `.\gradlew publishToMavenLocal` of the main project to put the plugin jar into the local maven repo.

2. Then run `gradle build` here.
2. Then run `..\..\gradlew clean build -i` here.

The build should fail due to duplicate licence files and manifests only, as the build.gradle suppresses checks on classes and directories.
3 changes: 2 additions & 1 deletion demo/shouldFail/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// ADDITIONALLY THIS DEMO USES THE OLD STYLE GRADLE DEP apply plugin

// expect failure from this build script because hamcrest-all contains hamcrest-core
// so there are lots of dupe'd resources
Expand All @@ -15,7 +16,7 @@ buildscript {
}

dependencies {
classpath "com.portingle:classpath-hell:1.7.0"
classpath "com.portingle:classpath-hell:1.8"
}
}

Expand Down
5 changes: 5 additions & 0 deletions demo/shouldPass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. First do a `.\gradlew publishToMavenLocal` of the main project to put the plugin jar into the local maven repo.

2. Then run `..\..\gradlew clean build -i` here.

The build should pass.
26 changes: 18 additions & 8 deletions demo/shouldPass/build.gradle
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
// ADDITIONALLY THIS DEMO USES THE NEW STYLE GRADLE DEP plugin id

buildscript {
dependencies {
classpath 'com.portingle:classpath-hell:1.7.0'
}
// OLD STYLE DEP
// dependencies {
// classpath 'com.portingle:classpath-hell:1.8'
// }

repositories {
mavenLocal()
mavenCentral()
mavenCentral()
}
}

plugins {
// NEW STYLE DEP
id('com.portingle.classpath-hell').version("1.8")
}

repositories {
mavenCentral()
mavenCentral()
}

apply plugin: 'com.portingle.classpathHell'
apply plugin: 'java'

// OLD STYLE DEP
//apply plugin: 'com.portingle.classpathHell'


dependencies {
implementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
Expand All @@ -28,10 +38,10 @@ classpathHell {
trace = true

// only scan one configuration as this makes the test's verification easier
configurationsToScan = [ configurations.runtimeClasspath ]
configurationsToScan = [configurations.runtimeClasspath]

// suppress a genuine dupe - one that is not an exact dupe
resourceExclusions = [ "META-INF/MANIFEST.MF" ]
resourceExclusions = ["META-INF/MANIFEST.MF"]

// configure automatic resolution of "benign" dupes
suppressExactDupes = true
Expand Down
8 changes: 7 additions & 1 deletion demo/shouldPass/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
rootProject.name = 'classpathHell-sample'
pluginManagement {
repositories {
mavenLocal() // allows picking local maven versions of classpath-hell
gradlePluginPortal()
}
}

rootProject.name = 'classpathHell-sample'

0 comments on commit f71d936

Please sign in to comment.