0

i´m trying to get a plugin to have the current version in a gradle kts file. I´m not able to get the apply for some reason, this is my code ->

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath("com.google.code.gson:gson:${rootProject.extra["gson_version"]}")
    }
}

plugins {
    id("me.tadej.versioning") version "0.2.0"
}

But i´m getting this error ->

"The plugins {} block must not be used here. If you need to apply a plugin imperatively, please use apply() or apply(plugin = "id") instead."

What i´m doing wrong here ?

Thanks!

EDIT: I tried to write this as:

import com.google.gson.Gson
import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.net.HttpURLConnection
import java.net.URL

plugins {
    id("me.tadej.versioning") version "0.2.0"
}
repositories {
    mavenLocal()
    mavenCentral()
}
dependencies {
    classpath("com.google.code.gson:gson:${rootProject.extra["gson_version"]}")
}

And got this error message:

ScriptCompilationException(errors=[ScriptCompilationError(message=Unresolved reference: gson, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (1:19)), ScriptCompilationError(message=Unresolved reference: classpath, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (17:5)), ScriptCompilationError(message=Unresolved reference: Gson, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (50:21)), ScriptCompilationError(message=Unresolved reference: Gson, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (100:16)), ScriptCompilationError(message=Unresolved reference: it, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (101:26)), ScriptCompilationError(message=Unresolved reference: it, location=/Users/develop/.gradle/.tmp/gradle-kotlin-dsl-14359683498958959271.tmp/jira.gradle.kts (101:40))])
    at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptModuleTo(KotlinCompiler.kt:187)
    at org.gradle.kotlin.dsl.support.KotlinCompilerKt.compileKotlinScriptToDirectory(KotlinCompiler.kt:148)
    at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$compileScript$1.invoke(ResidualProgramCompiler.kt:708)
    at org.gradle.kotlin.dsl.execution.ResidualProgramCompiler$compileScript$1.invoke(ResidualProgramCompiler.kt:85)
    at org.gradle.kotlin.dsl.provider.StandardKotlinScriptEvaluator$InterpreterHost$runCompileBuildOperation$1.call(KotlinScriptEvaluator.kt:162)...

Nicote Ool
  • 121
  • 8
  • 1
    Please update your question to include the code and errors, [not screenshots](https://meta.stackoverflow.com/q/285551/4161471). You are applying a plugin inside the `buildscript {}` block - [the plugins block should not be contained within any `{}` brackets](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block). – aSemy Nov 18 '22 at 20:30
  • Thanks Semy, i just edit as you requested, still having the same issue...perhaps I missed some config issue ? – Nicote Ool Nov 22 '22 at 14:30
  • You file is named `jira.gradle.kts`, so it's a 'script plugin'. [`extra` is part of the Kotlin DSL](https://gradle.github.io/kotlin-dsl-docs/api/org.gradle.kotlin.dsl/org.gradle.api.plugins.-extension-aware/extra.html), which is [not available inside script plugins](https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:accessor_applicability). Rather than using 'script plugins', it's much better to create buildSrc convention plugins https://stackoverflow.com/q/72113692/4161471 https://stackoverflow.com/q/71883613/4161471. But as a quick-fix, use `extensions.extraProperties` instead. – aSemy Dec 04 '22 at 11:55

0 Answers0