adjustments for Groovy 4 build
diff --git a/build.gradle b/build.gradle
index caffc17..0273f26 100644
--- a/build.gradle
+++ b/build.gradle
@@ -86,6 +86,8 @@
     relVersion = project.findProperty('releaseVersion')
     numVersion = relVersion?.find(/^[\d\.]+/)
     newRelease = numVersion?.endsWith('.0')
+    apacheGroupId = relVersion && relVersion[0] >= '4'
+    distParentDir = apacheGroupId ? "$stagingDir/subprojects/groovy-binary/build" : "$stagingDir/target"
     underVersion = relVersion?.replace('.', '_')?.replace('-', '_')?.toUpperCase()
     releaseBuild = !relVersion?.toLowerCase()?.contains('snapshot')
     stableBuild = releaseBuild && !relVersion?.toLowerCase()?.contains('alpha') && !relVersion?.toLowerCase()?.contains('beta') && !relVersion?.toLowerCase()?.contains('rc')
diff --git a/gradle/adhoc.gradle b/gradle/adhoc.gradle
index d8d2e31..6026328 100644
--- a/gradle/adhoc.gradle
+++ b/gradle/adhoc.gradle
@@ -117,5 +117,7 @@
         println "devWorkspace = $devWorkspace"
         println "releaseWorkspace = $releaseWorkspace"
         println "stagingWebsiteDir = $stagingWebsiteDir"
+        println "apacheGroupId = $apacheGroupId"
+        println "distParentDir = $distParentDir"
     }
 }
\ No newline at end of file
diff --git a/gradle/phase1.gradle b/gradle/phase1.gradle
index d0d4371..e4786b1 100644
--- a/gradle/phase1.gradle
+++ b/gradle/phase1.gradle
@@ -169,7 +169,7 @@
     group = "Pre-vote phase"
     description = "Publishes the Maven artifacts to the Apache staging repository"
     workingDir stagingDir
-    if (relVersion.startsWith('4.0')) {
+    if (apacheGroupId) {
         ext.theArgs = []
         if (Os.isFamily(Os.FAMILY_WINDOWS)) {
             theArgs += ['cmd', '/C', 'gradlew.bat']
@@ -196,14 +196,14 @@
 
 task copySvnDistro(type: Copy, dependsOn: [assumesPropsSet, prepareSvnDevWorkspace]) {
     description = "Creates the required tree structure for distribution"
-    from(relVersion.startsWith('4.0') ? "$stagingDir/subprojects/groovy-binary/build/distributions" : "$stagingDir/target/distributions")
+    from("$distParentDir/distributions")
     into "$devWorkspace/distribution"
     exclude 'apache-groovy-src-*'
 }
 
 task copySvnSources(type: Copy, dependsOn: [assumesPropsSet, prepareSvnDevWorkspace]) {
     description = "Creates the required tree structure for sources"
-    from(relVersion.startsWith('4.0') ? "$stagingDir/subprojects/groovy-binary/build/distributions" : "$stagingDir/target/distributions")
+    from("$distParentDir/distributions")
     into "$devWorkspace/sources"
     include 'apache-groovy-src-*'
 }
diff --git a/gradle/phase2.gradle b/gradle/phase2.gradle
index 93517ac..56527bd 100644
--- a/gradle/phase2.gradle
+++ b/gradle/phase2.gradle
@@ -99,7 +99,7 @@
         def build = builds.find {
             resp = artifactory.get(path: 'api/build/groovy/' + it.uri, contentType: JSON)
             assert resp.status == 200
-            def prefix = relVersion.startsWith('4.0') ? 'org.apache.groovy:groovy:' : 'org.codehaus.groovy:groovy:'
+            def prefix = apacheGroupId ? 'org.apache.groovy:groovy:' : 'org.codehaus.groovy:groovy:'
             def coreModuleId = resp.data.buildInfo.modules*.id.find{ it.startsWith(prefix) }
             def found = coreModuleId?.endsWith(':' + relVersion)
             println "${found ? 'FOUND' : 'SKIPPING'} $coreModuleId @ ${it.uri}"
@@ -112,17 +112,18 @@
             "dryRun" : ${project.hasProperty('dryRun').toString()},
             "publish" : true,
             "async" : false,
-            "targetRepo" : "distribution-repo",
+            "targetRepo" : "${apacheGroupId ? 'distribution-repo-apache' : 'distribution-repo'}",
             "sourceRepos" : ["libs-release-local"]
         }/
+        if (project.hasProperty('dryRun')) println body
         resp = artifactory.post(
                 path: "api/build/distribute/groovy/$buildNum",
                 body: body,
                 requestContentType: JSON
         )
-        assert resp.status == 200
         if (project.hasProperty('dryRun')) println resp.data
         else println resp.data.message
+        assert resp.status == 200
     }
 }
 
@@ -166,7 +167,7 @@
             "password" : "${project.findProperty('centralKey')}"
         }/
         def resp = bintray.post(
-                path: "groovy/versions/$relVersion", // apache-groovy?
+                path: "groovy/versions/$relVersion",
                 body: body,
                 requestContentType: JSON
         )
@@ -175,20 +176,18 @@
         println resp.data.messages.join('\n')
     }
 }
-synchronizeWithMavenCentral.onlyIf()
+synchronizeWithMavenCentral.onlyIf{ !apacheGroupId }
 
-// TODO decide if this should go via staging on artifactory
 task publishZipsOnBintray(dependsOn: [jiraCheckPhase2, assumesRelVersion]) {
     group = "Post-passed phase"
     description = "Publish distribution zips to bintray"
     doLast {
         def bintray = new RESTClient('https://api.bintray.com/content/groovy/maven/')
         bintray.headers['Authorization'] = 'Basic ' + "$bintrayUser:$bintrayKey".getBytes('iso-8859-1').encodeBase64()
-        fileTree("$stagingDir/target/distributions").files.each { File f ->
+        fileTree("$distParentDir/distributions").files.each { File f ->
             println "Uploading $f.name"
             def resp = bintray.put(
                     path: "groovy/$relVersion/${f.name}",
-//                    path: "apache-groovy/$relVersion/${f.name}",
                     body: f.bytes,
                     requestContentType: BINARY
             )
@@ -258,7 +257,7 @@
         ssh.run {
             session(remotes.ciServer) {
                 execute 'uname -a'
-                put from: "$stagingDir/target/distributions/apache-groovy-docs-${relVersion}.zip", into: '/var/www/docs/docs'
+                put from: "$distParentDir/distributions/apache-groovy-docs-${relVersion}.zip", into: '/var/www/docs/docs'
                 execute "rm -rf /var/www/docs/docs/groovy-${relVersion}/"
                 execute "unzip -d /var/www/docs/docs/ /var/www/docs/docs/apache-groovy-docs-${relVersion}.zip"
                 execute "chmod 664 /var/www/docs/docs/apache-groovy-docs-${relVersion}.zip"
@@ -364,7 +363,7 @@
 }
 waitForWebsitePublication.onlyIf{ releaseBuild }
 
-task publishToSDKman(dependsOn: [waitForWebsitePublication, maybeUpdateDocumentationSymlink, synchronizeWithMavenCentral, publishZipsOnBintray, uploadToApacheReleaseServer, sdkReleaseVersion]) {
+task publishToSDKman(dependsOn: [synchronizeWithMavenCentral, publishZipsOnBintray, uploadToApacheReleaseServer, waitForWebsitePublication, maybeUpdateDocumentationSymlink, sdkReleaseVersion]) {
     group = "Post-passed phase"
     description = "Publishes the release on SDKman"
 }