简体   繁体   中英

Gradle (Kotlin DSL): "Unresolved reference: proguard"

Im trying to get Proguard to work but Im still new to Gradle. My build gradle.kts haves an error (Unresolved reference: proguard), I cant create a proguard Task:

plugins {
    id("com.github.johnrengelman.shadow") version "5.2.0"
    java
    kotlin("jvm") version "1.3.61"
}

group = "*...*"
version = "*...*"

repositories {
    mavenCentral()
    jcenter() 
}

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    //*...*
    implementation("net.sf.proguard","proguard-gradle","6.2.2") //is this correct?
}

configure<JavaPluginConvention> {
    sourceCompatibility = JavaVersion.VERSION_1_8
}
tasks {
    compileKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    compileTestKotlin {
        kotlinOptions.jvmTarget = "1.8"
    }
    jar{
        manifest {
        attributes["Main-Class"] = "*...*"
        }
    }

    shadowJar{
        archiveBaseName.set("*...*")
        archiveClassifier.set("")
        archiveVersion.set("")
    }



    register<proguard.gradle.ProGuardTask>("myProguardTask") { //Unresolved reference: proguard

    }


}

This is not an Android Project Because Stackoverflow wants me to write more than just code: Im planing to somehow link the proguard output to the shadowjar task. If you know how to do it Im also interested to that (and I could not try it myself because of this problem).

You declared a dependency of proguard in project rather than for Gradle itself.

Move the dependency to the buildscript block:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'net.sf.proguard:proguard-gradle:6.2.2'
    }
}

Then you should be able to create your task.


Alternatively, you can declare the repository in settings.gradle.kts :

pluginManagement {
    repositories {
        jcenter()
    }
}

which will trim down the buildscript block in build.gradle.kts :

buildscript {
    dependencies {
        classpath("net.sf.proguard:proguard-gradle:6.2.2")
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM