Hi, I'm trying to use use a Gradle Groovy Plugin i...
# gradle
a
Hi, I'm trying to use use a Gradle Groovy Plugin in Gradle Kotlin DSL: https://github.com/mini2Dx/gettext/wiki/Gradle-Plugin The problem with the configurations, since configure the plugins in Gradle Kotlin is more type safe, I was able to migrate all the usages of Gradle Groovy plugins easily (like ShadowJar) except this one:
Copy code
// Example configurations
gettext {
    translations {
        srcDir = 'src'
        include = 'main/java/com/example/**/*.java'
        commentFormat = ' #. '
        outputFilename = 'translations.pot'
    }
}
Any idea how to use the exact same configurations in Gradle Kotlin DSL? it doesn't have
GetTextExtension
class and I tried with different ways but this is the only way that make the sync process work with no issues:
Copy code
tasks.withType(org.mini2Dx.gettext.plugin.task.GeneratePotTask::class) {
    srcDir = "src"
    include = "main/java/com/example/**/*.java"
    commentFormat = " #. "
    
    outputFile = layout.buildDirectory.file("gettext/translations.pot").get().asFile
}
But this code doesn't seems to have any affect at all, running the task
./gradlew generatePots
from GetText Gradle plugin won't work and generate the files for example, any idea how to use a Groovy plugin like this on Gradle Kotlin DSL? Thank you.
v
Did you follow that ill advice to use the legacy
apply
to apply the plugin, or did you properly apply the plugin through the
plugins { ... }
block?
a
I tried using the
plugins {}
block but it didn't work (maybe I has something wrong so I used the legacy
apply(plugin = "...")
I tried:
Copy code
plugins {
    id("org.mini2Dx.gettext") version "1.11.0"
}
But got:
Copy code
Plugin [id: 'org.mini2Dx.gettext', version: '1.11.0'] was not found in any of the following sources:
v
Then you do not get the type-safe accessors. Type-safe accessors are only generated for plugins you apply in the
plugins { ... ]
block and only for things those add without condition.
a
Any workaround for using it without the type-safe? maybe using
withGroovyBuilder
or something similar? but I still don't know how to use it and I tried but I always get type declaration error
v
You can just use the verbose API the accessors would use, no need for groovy builder
a
Can you give me an example? or a link maybe
v
If I were you, I'd make the
plugins { ... }
block work instead.
That plugin is a publishing bug, it does not publish the marker artifacts that are necessary to translate from the Plugin ID to the actual code artifact.
You should report that to this plugin
As a workaround you can use a resolution strategy in the plugin management block of your settings script to do the mapping manually
a
Sure I will do, so the alternative of:
Copy code
buildscript {
    repositories {
	mavenLocal()
        mavenCentral()
    }
    dependencies {
        classpath 'org.mini2Dx:gettext-gradle-plugin:1.7.1'
    }
}

...

project(":your-project") {
    apply plugin: "org.mini2Dx.gettext"
...
should be:
Copy code
plugins {
    id("org.mini2Dx.gettext") version "1.11.0"
}
But it didn't work for some reason, any idea?
v
Yes, I just told you what the problem is that you should report and how to work-around it
a
The problem is the gradle plugin project is no longer maintained, it's not up to me to replace it, I'm contributing to open source project
v
Well, then skip the reporting if you insist, but I also told you how to work-around in your build
Btw. that your
tasks.withType
is not working is, because there is no such task. The
gettext { translations { ... } }
is not configuring a task, but it is adding the
translations
element to the
gettext
named domain object container that would probably then add a task for that element.
And besides that, never use
tasks.withType(...) { ... }
but always
tasks.withType(...).confiugreEach { ... }
or you break task-configuration avoidance.
So in your settings script
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            when (requested.id.id) {
                "org.mini2Dx.gettext" ->
                    useModule("org.mini2Dx:gettext-gradle-plugin:1.11.0")
            }
        }
    }
}
And in your build script then
Copy code
plugins {
    id("org.mini2Dx.gettext")
}
and
Copy code
val translations by gettext.registering {
    srcDir = "src"
    // ...
}
But even if the project is unmaintained, you should imho still report the error. Could well be that at some point someone is picking up the project and then it is better the issue is already reported.
a
I will file an issue, should I include your name ?because some of the information mentioned in the issue is written by you
v
However you like 🙂
a
Thank you, I was finally able to sync the project successfully, while it doesn't fix the issue (running
./gradlew generatePots
task cause failure that wasn't in the groovy code and might be not related to the plugin itself) but at least I'm getting a different error:
Copy code
For more information, please refer to <https://docs.gradle.org/8.7/userguide/validation_problems.html#ignored_annotations_on_field> in the Gradle documentation.
  - Type 'org.mini2Dx.gettext.plugin.task.GeneratePotTask' field 'exclude' without corresponding getter has been annotated with @Input, @Optional.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'exclude'.
      2. Remove the annotations on 'exclude'.
    
    For more information, please refer to <https://docs.gradle.org/8.7/userguide/validation_problems.html#ignored_annotations_on_field> in the Gradle documentation.
  - Type 'org.mini2Dx.gettext.plugin.task.GeneratePotTask' field 'excludes' without corresponding getter has been annotated with @Input, @Optional.
    
    Reason: Annotations on fields are only used if there's a corresponding getter for the field.
    
    Possible solutions:
      1. Add a getter for field 'excludes'.
      2. Remove the annotations on 'excludes'.
v
You probably also update Gradle at the same time? That plugin is most probably not compatible with your new Gradle version.
a
It was the same Gradle version (I'm not sure yet but I will check it in a moments)
v
Or you also update the version of that plugin?
Just using Kotlin DSL instead of Groovy DSL should not influence whether you get that error I'd say
a
I know I'm asking from you more than I should, I tested the previous version before migrating to Kotlin DSL and it seems to work even with Gradle 8.7, but I noticed I did one change, in the groovy code, they used the GetText plugin from a fork that is 5 commits behind the original one, the old groovy code:
Copy code
buildscript {
    repositories {
        mavenCentral()
        maven {
            url '<https://jitpack.io>'
            content {
                includeGroup "com.github.RyanTheAllmighty.gettext"
            }
        }
    }
    dependencies {
        classpath 'com.github.RyanTheAllmighty.gettext:gettext-gradle-plugin:aab5c30bf8'
    }
}

apply(plugin = 'org.mini2Dx.gettext')
Any idea to apply the plugin from this repository/buildscript in Gradle Kotlin DSL so instead of
Copy code
"org.mini2Dx.gettext" ->
                    useModule("org.mini2Dx:gettext-gradle-plugin:1.11.0")
Will use the forked one, so I can test it.
v
image.png
a
After some testing, it appears the problem was because of using the original repository, I will try to use the forked one
v
Another thing to report 🙂
And another reason to strongly consider switching to an alternative if it really is unmaintained. Compatibility will not improve with newer Gradle versions.
a
Yes, I will do it right after finishing the workaround, So we only have to update the code:
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            when (requested.id.id) {
                "org.mini2Dx.gettext" ->
                    useModule("org.mini2Dx:gettext-gradle-plugin:1.11.0")
            }
        }
    }
}
To use the fork one instead of the original gradle plugin, but I'm still not sure about this, I tried updating the code to:
Copy code
pluginManagement {
    resolutionStrategy {
        eachPlugin {
            repositories {
                mavenCentral()
                maven {
                    setUrl("<https://jitpack.io>")
                    content {
                        includeGroup("com.github.RyanTheAllmighty.gettext")
                        includeGroup("com.github.ATLauncher.gradle-macappbundle")
                    }
                }
            }
            when (requested.id.id) {
                "org.mini2Dx.gettext" ->
                    useModule("com.github.RyanTheAllmighty.gettext:gettext-gradle-plugin:aab5c30bf8")
            }
        }
    }
}
and I'm getting this error:
Plugin [id: 'org.mini2Dx.gettext', artifact: 'com.github.RyanTheAllmighty.gettext:gettext-gradle-plugin:aab5c30bf8'] was not found in any of the following sources:
v
Well, as the fork is not published, you probably need to add the dratted JitPack as plugin repository. But at least use a repository content filter to only look for that plugin in it.
a
I'm not sure where the fork is published (probably in Jitpack), the old groovy code was using the following to use GetText from the fork
Copy code
buildscript {
    repositories {
        mavenCentral()
        maven {
            url '<https://jitpack.io>'
            content {
                includeGroup "com.github.RyanTheAllmighty.gettext"
            }
        }
    }
    dependencies {
        classpath 'com.github.RyanTheAllmighty.gettext:gettext-gradle-plugin:aab5c30bf8'
    }
}

apply plugin: 'org.mini2Dx.gettext'
v
Yes, as I said. But don't do the
repositories
in the
eachPlugin
, that is just visual clutter. It belongs directly inside
pluginManagement
Adding
Copy code
maven("<https://jitpack.io>") {
    content {
        includeGroup("com.github.RyanTheAllmighty.gettext")
    }
}
as plugin repository and switching to
useModule("com.github.RyanTheAllmighty.gettext:gettext-gradle-plugin:aab5c30bf8")
works fine here
a
Don't know why but for some reason when adding:
Copy code
repositories {
            mavenCentral()
            maven("<https://jitpack.io>") {
                content {
                    includeGroup("com.github.RyanTheAllmighty.gettext")
                }
            }
        }
In the
resolutionStrategy
will cause all the other plugins to not be found:
Copy code
Plugin [id: 'org.example.plugin', version: '0.6.1'] was not found in any of the following sources:
v
Well, sure, by defining custom repositories, you remove the default
gradlePluginPortal()
which serves most plugins
a
That make sense (I saw this before but didn't really know what it's for) it seems to be working (Might need more testing from my side) but it was all thanks to you.
👌 1