I have a code in lagacy style: ```buildscript { ...
# gradle
z
I have a code in lagacy style:
Copy code
buildscript {
    repositories {
        maven {
            url = uri("<https://files.minecraftforge.net/maven>")
        }
        mavenCentral()
    }
    dependencies {
        classpath("net.minecraftforge.gradle", "ForgeGradle", "5.+") {
            isChanging = true
        }
    }
}
How can I rewrite it into apply(plugin="smth") style? This does not work:
Copy code
repositories {
   maven(url = "<https://maven.minecraftforge.net>")
   mavenCentral()
}

apply(plugin = "net.minecraftforge.gradle:ForgeGradle:5.+")
v
apply(plugin = ...
is the legacy style. Btw
isChanging
is not appropriate unless they change artifacts of the same version.
z
Ok, how i can rewrite it in lagacy style?
v
What do you mean by rewrite? Your initial example already is the legacy style, it just misses the apply call
g
There are a few things which you should understand before trying to rewrite it
1. buildscript { repositories {} } is repository for plugins, your “new style” doesn’t work because you declare rpository for project dependencies, not for plugins
New way to declare repos for plugins is (NOTE: It’s in settings.gradle, because it must be declared before build.gradle excecution:
Copy code
// settings.gradle/settings.gradle.kts
pluginManagement {
    repositories {
        ...
    }
}
so in your case
will be something like:
Copy code
maven("<https://files.minecraftforge.net/maven>")
mavenCentral()
but probably what you actuall want is:
Copy code
gradlePluginPortal()
maven("<https://files.minecraftforge.net/maven>")
mavenCentral()
to get all default gradle plugins (also there is a chance that yopu don’t need mavenCentral, but nothing bad with it
2. Second pont, that actual new way to apply plugins is to use plugins dsl, more details: https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block
using
plugins.apply
is legacy mechanism as Björn is pointed out
3. For new plugins dsl you cannot just use dependency id, because plugins dsl works only with plugin id, which looks similar to dependency declaration, but it’s different, it’s essentially unique plugin id. This a special Gradle mechanism to resolve plugin, and to make it work plugin should be published with plugin marker, which is not always the case, you can see this section it shows how to use plugins which do not have plugin marker: https://docs.gradle.org/current/userguide/plugins.html#sec:plugin_markers
4. Most of plugins are published on Gradle Plugin portal, if it’s true for your plugin, you don’t need any additional repositories, you just add it to plugins block
I don’t know anything about net.minecraftforge.gradle:ForgeGradle plugin, simple search shows this: https://plugins.gradle.org/plugin/net.minecraftforge.gradle.forge But looks that it’s different version completely, but just as Idea for you
so direct (or mostly direct) convertation of your code will looks something like this: (I do not now plugin id for this ForgeGradle plugin, but let’s assume that it
net.minecraftforge.gradle.forge
(same as plugin published on Gradle Plugins portal)
Copy code
// settings.gradle/settings.gradle.kts
pluginManagement {|
    resolutionStrategy {
        eachPlugin {
            // NOTE: This code used to map plugin id to dependency manually
            // I don't know is it needed for you or not
            if (requested.id.namespace == 'net.minecraftforge.gradle.forge') {
                // This is your old plugiun dependencyu
                // NOTE: I do not think that dynamic versions work for plugins,
                // but it may changed in the latest version,
                // anyway highly recommend to use specific version instead even if it works
                useModule("net.minecraftforge.gradle:ForgeGradle:5.+")
            }
        }
    }
    repositories {
        gradlePluginPortal()
        maven("<https://files.minecraftforge.net/maven>")
        mavenCentral()
    }
}

// build.gradle.kts
plugins {
    id("net.minecraftforge.gradle.forge")
}
if you use plugin which already published on Gradle plugin portal you completely remove all config in settings.gradle.kts
e
upstream looks kinda insane, https://github.com/MinecraftForge/ForgeGradle/blob/FG_5.0/build.gradle multiple sourcesets instead of projects, then bundling them…
v
He said he wants to rewrite IN legacy style, that's why I didn't elaborate on non-legacy style. And besides that I happen to know that the ForgeGradle plugin does many insanely dirty things and cannot be used with the new plugins DSL, which indeed points in the direction that OP wants (because he needs to) use the legacy style. 😉
z
Thanks, it works!
👌 1
But if I need to use exactly apply(...)?
Copy code
eachPlugin
works only with plugins from plugins block
v
As I said, all that gildor said was about the new way, not the legacy way. ForgeGradle is misbehaving and is not compatible with the new way. So just forget what he said and read again what I said.