Przeglądaj źródła

fix: add repo to all projects

Siqi Wang 1 rok temu
rodzic
commit
5177afb58c

+ 0 - 5
build.gradle.kts

@@ -7,18 +7,13 @@ version = "1.0-SNAPSHOT"
 
 repositories {
     mavenCentral()
-    maven { url = uri("https://repo.gradle.org/gradle/libs-releases") }
 }
 
 dependencies {
     testImplementation(kotlin("test"))
-    implementation("org.gradle:gradle-tooling-api:7.5.1")
     // https://mvnrepository.com/artifact/org.apache.groovy/groovy
     implementation("org.apache.groovy:groovy:4.0.24")
     implementation("org.apache.groovy:groovy-console:4.0.24")
-
-    // The tooling API need an SLF4J implementation available at runtime, replace this with any other implementation
-    runtimeOnly("org.slf4j:slf4j-simple:1.7.10")
 }
 
 tasks.test {

+ 9 - 0
src/main/kotlin/RootGradleVisitor.kt

@@ -32,6 +32,15 @@ class RootGradleVisitor : ClassCodeVisitorSupport() {
                 val mavenRepo = createClassPathExpression()
                 dependencies.statements.add(0, mavenRepo)
             }
+        } else if (call.methodAsString == "allprojects") {
+            val buildscriptBlock = call.arguments as ArgumentListExpression
+            val closure = buildscriptBlock.expressions[0] as ClosureExpression
+            val repositoriesBlock = findRepositoriesBlock(closure)
+            val repositories = (repositoriesBlock?.expressions?.first() as? ClosureExpression)?.code as? BlockStatement
+            if (repositories != null) {
+                val mavenRepo = createMavenRepoExpression()
+                repositories.statements.add(0, mavenRepo)
+            }
         }
         super.visitMethodCallExpression(call)
     }

+ 1 - 0
src/main/kotlin/main.kt

@@ -21,6 +21,7 @@ fun patchGradle(file : File, root : Boolean) {
     }
 
     for (node in ast) {
+//        if(!root)
         node.visit(visitor)
     }