plugin-development
  • a

    Andres Almiray

    11/08/2022, 5:52 AM
    Hello everyone, I’ve seen downgraded service from the Gradle Plugin Portal for the second time in a span of 10 days (1st time on Oct 30th, 2nd time on Nov 7th). Building on a pristine environment on GitHub Actions leads to unresolved plugins. However, builds succeed when local caches are available. Does anyone know if there’s a status page for the GPP? Anyone else has a clue what may be happening? Apparently I’m not the only one that has had their builds impacted during these two occasions.
  • c

    Chris Lee

    11/08/2022, 5:21 PM
    Working through making things work with project isolation, to the extent currently possible; have the below use-cases that I’m not able to find alternative solutions for 1. Access to root project; in a convention plugin:
    group = rootProject.group
        version = rootProject.version
    2. Access to root project; in a convention plugin, grab the version catalog:
    public fun Project.versionCatalogs(action: VersionCatalogsExtension.() -> Unit) {
        rootProject.extensions.configure(action)
    }
    3. Use of allprojects; in an init script (custom Gradle distribution):
    allprojects {
        // for the script itself, e.g. plugins
        buildscript {
            configurations.all {
                resolutionStrategy {
                    cacheDynamicVersionsFor(1, TimeUnit.HOURS)
                    cacheChangingModulesFor(5, TimeUnit.MINUTES)
                }
            }
        }
    
        configurations.all {
            resolutionStrategy {
                cacheDynamicVersionsFor(2, TimeUnit.HOURS)
                cacheChangingModulesFor(5, TimeUnit.MINUTES)
            }
        }
    }
  • Javi

    Javi

    11/09/2022, 4:48 PM
    Is it possible to build a
    RegularFileProperty
    from a
    DirectoryProperty
    ? I only see
    Provider<RegularFile>
    mappers
  • s

    Satyarth Sampath

    11/10/2022, 4:19 AM
    Hey folks, Is there a way for me to know when an extension for my plugin has been configured?
  • Andrew Grosner

    Andrew Grosner

    11/11/2022, 7:55 PM
    hi i am trying to run
    commandLine("diff", "<($command1)","<($command2)")
    in an
    Exec
    task (w/
    executable("zsh")
    ). Running it locally in zsh produces a diff:
    diff <($command1) <($command2)
    but in the gradle project runner (running inside a jupiter testkit test) it receives the error:
    diff: <($command1): No such file or directory
    diff: <($command2): No such file or directory
    excuse my lack of understanding, but why would this be the case?
  • El Zhang

    El Zhang

    11/13/2022, 1:39 AM
    Hi everyone, any ideas on getting the integrationTest (created by test suites apis) works with GradleRunner.withPluginClasspath() , I added
    dependsOn("pluginUnderTestMetadata")
    , but the integrationTest task still throws:
    org.gradle.testkit.runner.InvalidPluginMetadataException: Test runtime classpath does not contain plugin metadata file ‘plugin-under-test-metadata.properties’
    testing {
        suites {
            val test by getting(JvmTestSuite::class) {
                useJUnitJupiter()
            }
    
            val integrationTest by registering(JvmTestSuite::class) {
                dependencies {
                    implementation(project)
                }
                targets {
                    all {
                        testTask.configure {
                            dependsOn("assemble")
                            dependsOn("pluginUnderTestMetadata") // even though I added this
                            shouldRunAfter(test)
                        }
                    }
                }
            }
        }
    }
    
    tasks.withType<PluginUnderTestMetadata>().configureEach {
        dependsOn("compileKotlin", "compileTestKotlin", "compileJava", "compileTestJava")
        dependsOn("processResources", "processTestResources")
    
        pluginClasspath.setFrom(/* reset */)
    
        pluginClasspath.from(configurations.compileClasspath)
        pluginClasspath.from(configurations.testCompileClasspath)
        pluginClasspath.from(configurations.getByName("integrationTestCompileClasspath"))
        pluginClasspath.from(configurations.runtimeClasspath)
        pluginClasspath.from(provider { sourceSets.getByName("integrationTest").runtimeClasspath.files })
    }
  • d

    Daren Klamer

    11/15/2022, 12:05 PM
    Can anyone help me with my convention plugins that i published? I'm not sure how to use them in another project. the co-ordinates of the jar is say
    foo.bar.my-plugins:1.0-SNAPSHOT
    and the convention script is called
    my.conventions.helloWorld.gradle
    . I wasa following the docs here
  • d

    Daren Klamer

    11/16/2022, 2:02 PM
    gi all, me again (b00), is there a nice way to access a property in the gradle.properties file in ~/.gradle from a plugin?
  • a

    Andres Almiray

    11/17/2022, 1:32 PM
    Hello everyone. As you may be aware Gradle has a couple of settings to enabled reproducible archives. In particular
    preserveFileTimestamps = false
    will pick a given date that matches
    02-01-1980 00:00
    . Has anyone found a way to set a different fixed date? I’d rather have a fixed date such as “last commit time” when available, resorting to Gradle’s default when it isn’t.
  • d

    Daren Klamer

    11/17/2022, 2:17 PM
    hey all, what's the nicest way to get a plugin to do something right at the end (say, after all tests have run, even if they failed)?
  • d

    Daren Klamer

    11/17/2022, 2:21 PM
    wanted to do some cleanup
  • c

    Chris Lee

    11/18/2022, 5:04 PM
    have a set of JSON files included in a custom plugin (e.g.
    /whatever/a.json, b.json, …
    ). looking to include them in a configuration (e.g.
    someConfig('a.json')
    ). One can of course pull them from the classpath to temp dir and use
    files
    or similar; are there alternate approaches to resolve them directly from classpath?
  • d

    Daren Klamer

    11/19/2022, 4:55 AM
    Hi all, I wanted to write a plugin (last one!) that customised the maven publish process. I figured instead of copying/pasting the config in every repo I could write a plugin for everyone. I think i have repositories working, but don't know how to add the
    from components.java
    part in code. My plugin is based off of this code here https://stackoverflow.com/questions/61713342/configure-gradle-maven-publish-plugin-directly-from-my-custom-plugin
  • Javi

    Javi

    11/20/2022, 12:34 PM
    Is it possible to use composition instead of inheritance when using a base class task? Use case in 🧵
  • c

    Clayton Walker

    11/22/2022, 6:53 PM
    It is possible to configure an external task (say a check provided by another plugin) to not fail on failure? Like a post-task run action that could optionally continue (say mark the task as skipped)
  • m

    melix

    11/24/2022, 2:08 PM
    hey! I have a task which is out-of-date because of a nested property. It happens that that particular task doesn't care about this property, so it shouldn't be considered an input. Is it possible to tell Gradle to ignore that property for a particular task (note that the object is configuration which is shared by multiple tasks, in a 3rd party project, so I cannot annotate the property with
    @Internal
    )
  • t

    thadhouse

    11/25/2022, 5:36 AM
    Is there a service I can inject to get a
    Gradle
    instance? So I can create a shared build service, without having to manually inject either a
    Gradle
    or a
    Project
    instance?
  • m

    melix

    11/25/2022, 4:00 PM
    just throwing out an idea, but it would be nice if TestKit had a way to mock the execution of a task.
  • Javi

    Javi

    11/28/2022, 3:02 PM
    Is it possible to stop a task execution programmatically with Gradle TestKit?
  • n

    Nicola Corti

    11/28/2022, 5:05 PM
    Q: What is the best practice to let a project access the extension of another one? I suspect the answer will be: “You don’t” but due to setup of my projects, I’m still curious in brainstorming about this, if someone ever experience this. I have: • Project
    :app
    where my plugin registers
    fooExtension
    and
    fooTask
    • Project
    :library
    where my plugin registers
    feeExtension
    and
    feeTask
    I’d like to have some of the fields inside
    fooExtension
    to be used inside
    feeTask
    as well. In a sense, my library tasks should honor some of the configurations the user specifies inside the app in the
    fooExtension
    I’ve tried registering an extension on the rootProject, registering a task on the rootProject and wiring it, using properties… All the solutions looks suboptimal to me.
  • c

    Clayton Walker

    11/29/2022, 1:38 AM
    I’ve switched a
    buildSrc
    to an
    includeBuild
    and now my kotlin
    plugins {
        com.example.`my-convention`
    }
    doesn’t work and I have to specify them as
    plugins {
        id("com.example.my-convention")
    }
    am I missing a plugin in my includeBuild’s build.gradle.kts?
  • Paul Blundell

    Paul Blundell

    11/30/2022, 4:45 PM
    Trying to add a convention plugin, but I’m missing something to get the
    includeBuild
    short hand to work. Any pointers of where to look? Works:
    includeBuild("my/nested/cool-plugin") {
        dependencySubstitution {
            substitute(module("com.blundell.plugin:cool-plugin"))
                    .using(project(":plugin"))
        }
    }
    Does not work:
    includeBuild("my/nested/cool-plugin")
  • ephemient

    ephemient

    11/30/2022, 6:28 PM
    is there any way to have optional BuildServiceParameters? if I write
    abstract class HttpServerService : BuildService<HttpServerService.Parameters>, AutoCloseable {
        interface Parameters : BuildServiceParameters {
            @get:Optional val host: Property<String>
            @get:Optional val port: Property<Int>
            @get:Optional val backlog: Property<Int>
            val root: DirectoryProperty
        }
    the annotation doesn't make any difference,
    gradle.sharedServices.registerIfAbsent
    will throw if I don't set all of them
  • a

    Andres Almiray

    11/30/2022, 7:50 PM
    Hello everyone. A user has reported an error where a file is kept open when running a build on Windows which prevents
    gradlew clean
    from working as expected. If the Gradle daemon is killed then the clean operation succeeds. I’ve added what I thought was a fix: close the offending file
    trace.log
    (or what I think is the offending file based on the stacktrace) before the build is finished yet the problem persists. A full copy of the stacktrace can be found at https://github.com/jreleaser/jreleaser/issues/1074#issuecomment-1332660055. I’ve verified that the file is indeed closed at the right time. I’m left scratching my head with this one. Anyone seen a similar error such as
    java.io.IOException: Unable to delete directory
    ?
  • Guilherme Lima Pereira

    Guilherme Lima Pereira

    12/01/2022, 1:56 PM
    Has anyone had a hard time adding
    BuildServiceParameters
    to a
    BuildService
    ? I've been running one perfectly with
    BuildServicesParameters.None
    , but when I try to add parameters I receive this:
    * What went wrong:
    An exception occurred applying plugin request [id: 'vpn-check']
    > Failed to apply plugin 'vpn-check'.
       > Could not create an instance of type vpn.BuildOperationListenerService$Parameters.
          > Could not generate a decorated class for type BuildOperationListenerService.Parameters.
             > Cannot have abstract method Parameters.isVpnConnected().
  • Paul Blundell

    Paul Blundell

    12/01/2022, 2:15 PM
    if my plugin task generates a list of gradle tasks that need running. Is it best to set these as an output and execute them in a new task, or can I just execute them in the same task?