https://gradle.com/ logo
Docs
Join the conversationJoin Slack
Channels
android
caching
community-news
community-support
config-avoidance
configuration-cache
contributing
dependabot
dependency-management
design
design-specs
developer-productivity-engineering
docs
dpe-summit
feed
file-system-watching
flutter
general
gradle-enterprise
jobs
kotlin-dsl
linen
maven
migrating-from-ant
migrating-from-maven
native
performance
playframework
plugin-development
releases
roadmap
self-promotion
Powered by Linen
plugin-development
  • m

    Michał Klimczak

    02/03/2023, 3:58 PM
    is there any comprehensive guide for the kotlin versions compatibility when developing plugins? I have a plugin which uses
    kotlin-jvm
    and
    kotlinx-serialization
    plugins itself as well as
    kotlin-dsl
    . Using kotlin-dsl plugin enforces the use of kotlin 1.6.21 for all other plugins. This, in turn, means that I have to use some dependencies in their old versions. I tried using kotlin 1.7.20 for kotlin-jvm and serialization and it seemed to work, but then it has blown up with some NoSuchMethodException on some
    File
    api when I built an app which was using my plugin - specifically on a kapt step. This all seems really hard to follow, but from these experiences my understanding is that
    kotlin-dsl
    plugin kind of defines everything else. Is that right?
    v
    ł
    p
    • 4
    • 25
  • m

    Michał Klimczak

    02/07/2023, 3:34 PM
    I'm struggling with adding classes that are generated in a plugin to Android source sets. They are not picked up by the compiler, nor by intellij. Simplified example:
    NamedDomainObjectContainer<AndroidSourceSet> sourceSets = project.getExtensions().getByType(AppExtension.class).getSourceSets()
    
    File outputDir = new File(project.getBuildDir()+ File.separator+"generated"+File.separator+"source");
    
    ...
    greeterFile.writeTo(outputDir);
    sourceSets.getByName("main").getJava().srcDir(outputDir);
    The file is properly created and there are no warnings, but the class is not on classpath after the project is built - can't be used in android project. The source set "main" is fine, when I use something dummy, it fails. I tried getKotlin() instead of getJava(). I tried srcDir, srcDirs and other functions. I read somewhere, that you need to "register" these source sets after adding them, but this is probably some old api, since I don't see any register methods.
    v
    • 2
    • 9
  • b

    Big Chungus

    02/10/2023, 3:41 PM
    Is it possible to somehow suppress gradle accessor generation for some of my plugin's extensions? Some annotation or simmilar. I'm trying to register a function that takes Action argument as an extension and I get 2 accessors being generated 1. Property accessor (I want to keep this) 2. Function accessor to configure it (I need to get rid of it) #2 overshadows my actual function property and leaves no way to call it rather than configure it.
    c
    v
    • 3
    • 2
  • t

    twisterrob

    02/13/2023, 11:21 AM
    We're trying to achieve a similar DSL to
    repositories.mavenCentral()
    , which means you can do
    stuff.foo()
    or
    stuff { foo() }
    which creates a "well-known" instance in a
    NamedDomainObjectContainer
    . Currently this is done via Kotlin delegation, but it needs internal API usage.
    open class DefaultStuffContainer @Inject constructor(delegate: NamedDomainObjectContainer<Stuff>) : NamedDomainObjectContainer<Stuff> by delegate {
        fun foo(): Stuff = TODO()
    
        override fun configure(configureClosure: Closure<*>): NamedDomainObjectContainer<NexusRepository> =
            // Heavy use of internal API, copied from AbstractNamedDomainObjectContainer
            ConfigureUtil.configureSelf(configureClosure, this, NamedDomainObjectContainerConfigureDelegate(configureClosure, this))
    }
    what would be the proper way to achieve the same as
    RepositoryHandler
    (which has named methods and is also a container) with public APIs only? because the only way I can see now is to extend
    DefaultNamedDomainObjectSet
    directly, which is internal API.
    v
    • 2
    • 20
  • m

    melix

    02/14/2023, 10:39 AM
    Hey folks, it seems that Gradle 8 reintroduced a change which had been reverted : https://github.com/micronaut-projects/micronaut-core/discussions/8772 Unfortunately I didn't get an answer about how to properly solve this, and didn't get a deprecation warning for this change so it was unnoticed 😞
    v
    s
    • 3
    • 17
  • m

    melix

    02/15/2023, 11:54 AM
    daaaaaaaaaaaaannngggg
    c
    m
    • 3
    • 23
  • m

    Martin

    02/16/2023, 12:43 PM
    Is there some recommendations/guidance how to expose/publish artifacts from a plugin? I have a plugin that produces metadata files. There might be several of these metadata files for a single project. A few questions I'm having: 1. Should my plugin create its own publication(s) or just expose software components and leave the decision to publish to users? 2. Or should it "piggy back" on the Kotlin software component and add variants there (the metadata files are not usable without a matching kotlin jar/klib file)? 3. Should each file be its own artifact or should I "group" everything into a single zip and leave it up to consumer to loolup the "good" artifact? I hope it make sense? Looks like the Kotlin MPP plugin went with multiple publications but it could as well have been a single one with variants? How do I choose?
  • d

    Dmitriy Voronin

    02/17/2023, 2:05 PM
    Hello, how do you log in SharedBuildServices? Seems like service injection not working there? Also passing logger as parameter is not an option as it's not serializable and i'am not sure if any of projects has same lifecycle as buildService Getting slf4j logger in BuildService seems like not producing any logs Simple System.out/err is working, but i just wondering if there is a way to obtain gradle native logger instance?
    a
    c
    t
    • 4
    • 10
  • c

    Christoph Loy

    02/18/2023, 11:25 PM
    Hey guys 🙂 I spent the last weeks developing an alternative to ben-manes versions plugin that does not use any deprecated API and is compatible with Configuration Cache. I am planning to release a first version in a few days. Now I know, that this is a lot to ask, but could anyone of you give it a quick look to check for any glaring issues with it? I want the plugin to be lean and simple. Configuration should be kept to a minimum and it should work by just applying it to the root project. You can find it here: github.com/beatbrot/gradle-dependency-report Thanks a lot!
    t
    • 2
    • 3
  • d

    David Gregory

    02/20/2023, 6:06 PM
    Hi folks! I’ve been working on a miniature JVM functional programming language for a little while (https://github.com/DavidGregory084/mina) and I’m at that stage in the project where I’m considering my options w.r.t. build tool integration. I already have lots to do so I really don’t want to write yet another JVM build tool, and I’m already using Gradle to build the compiler and all of the associated tooling so it’s a natural choice. However, what I’ve found so far is that the existing JVM language plugins are all either in the gradle repo and heavily use Gradle internal APIs (Java, Scala, Groovy) or they don’t use the public Gradle APIs for common things (e.g. Kotlin has its own compiler daemon and doesn’t use the DaemonCompiler infrastructure like the others). I can also see that the internal APIs for JVM languages are under heavy development at the moment so they’re a quick-moving target to try and integrate against. I have many questions (sorry): • Is there any example of the current best practice w.r.t. integrating language support into Gradle? My current (dummy) implementation at https://github.com/DavidGregory084/mina/tree/main/gradle-plugin is mostly templated from the existing Scala and Groovy plugins, but I’ve seen comments from Gradle contributors suggesting that they no longer suggest using the DaemonCompiler APIs (e.g. https://github.com/gradle/gradle/issues/11353#issuecomment-553593847), and indeed the Kotlin Gradle plugin uses some aspects of the Worker API in its implementation. • How can I gain some awareness of the deprecations that are planned in the internal JVM plugin APIs, and are methods of migrating to the newer APIs documented anywhere? For example, in the Scala plugin sources, I can see that as part of the SourceSet deprecations, DefaultScalaSourceSet will be removed (https://github.com/gradle/gradle/blob/9a14bd5cd426bdaf22fb5ff6f0ea51649599e135/sub[…]src/main/java/org/gradle/api/plugins/scala/ScalaBasePlugin.java). I tried to get ahead of this by using a SourceDirectorySet in my plugin, but it doesn’t work because part of SourceDirectorySet is not compatible with ObjectFactory’s requirements about abstract methods. • What’s the best way to extract compiler diagnostics from a JVM language build task? I’ve looked through the tooling API but I can’t see anything that really addresses returning diagnostics like compiler errors and warnings from a build task. At present my language server plugin is calling the compiler directly so returning diagnostics to an editor is easy, but once Gradle is added as an intermediary this seems to become a lot more difficult. • Is there any interest in integrating with the Build Server Protocol (https://build-server-protocol.github.io/), which addresses similar problems to the Language Server Protocol (https://microsoft.github.io/language-server-protocol/) in providing a protocol for editors and language servers to talk to build tools? • When implementing tasks like compilation with the Worker API or the DaemonCompiler APIs, how can a plugin place its own classes onto the class path for forked or classloader isolated workers? My current DaemonCompiler-based implementation has hit a brick wall because I don’t know how to add my own plugin’s classes here and experience ClassNotFoundExceptions. The Gradle JVM language plugins cheat doubly here, both because they are hosted within Gradle’s codebase and because they are using hardcoded classpaths provided by Gradle’s ClassPathRegistry. Rewrote things using Worker API instead!
    e
    • 2
    • 11
  • l

    Leon Linhart

    02/20/2023, 9:42 PM
    Is there a way to set a
    org.gradle.api.provider.Property
    lazily with the option to have it default to its convention? All
    set
    overloads seem to disallow this. I want to change the value of a property of a third-party task depending on some configuration option. For this purpose, I'd like to use a
    gradleProperty
    provider (etc.) to derive the value for the property. However, it should also be possible for the task's property to fall back to its convention in some cases. Since there is no way to access the provider for the convention, I'm not sure how to express this.
    v
    • 2
    • 3
  • m

    Michał Klimczak

    02/21/2023, 9:52 AM
    how do I include a gradle plugin from jar? In settings.gradle.kts I tried things like:
    pluginManagement { include("plugins/my-plugin.jar") }
    pluginManagement { includeBuild("plugins/my-plugin.jar") }
    pluginManagement { include("plugins") }
    pluginManagement { includeFlat("plugins") }
    pluginManagement {
        repositories {
            flatDir {
                dir("plugins")
            }
        }
    }
    Or maybe there's a better way of including a closed source plugin in a project?
    n
    v
    • 3
    • 37
  • l

    Leon Linhart

    02/21/2023, 12:39 PM
    Running into a lot of annoyances while upgrading some stuff to Gradle 8. I'm curious about the reasoning behind this restrictions for forkOptions of
    JavaCompile
    tasks:
    String customExecutablePath = forkOptions.getExecutable();
    JavaExecutableUtils.validateExecutable(
        customExecutablePath, "Toolchain from `executable` property on `ForkOptions`",
        toolchainExecutable, "toolchain from `javaCompiler` property");
    (https://github.com/gradle/gradle/blob/7dec5105c7585151d7339beddfc549e04697a9cd/sub[…]ava/src/main/java/org/gradle/api/tasks/compile/JavaCompile.java) This effectively seems to prevent forking with a custom compiler executable as there is no supported way to define a custom
    JavaCompiler
    instance, no? (@Alex Semin Git blame spits out your name. Could you please have a look at this?)
    t
    v
    w
    • 4
    • 19
  • d

    Daren Klamer

    02/24/2023, 4:57 AM
    hi all, is it possible to have the groovy-gradle-plugin use a custom dir for source files? I wanted to replace things in the gradle plugins i wrote with system properties at build time using the ant ReplaceTokens feature
    v
    • 2
    • 4
  • c

    Christoph Loy

    02/24/2023, 6:38 PM
    Hey guys 🙂 Is there some way to declare a dependency to "allprojects" and then let variant-aware sharing do the rest? What I basically want to say is: "Give me all artifacts from all projects that match these attributes. If a project does not publish such an artifact, that's okay".
    a
    v
    • 3
    • 14
  • d

    David Ankin

    02/24/2023, 10:35 PM
    tl;dr: how should invalidate a test task on purpose, without uptodate.when false?
    t
    m
    v
    • 4
    • 12
  • r

    Roberto Fuentes

    02/27/2023, 3:31 PM
    Hey newbie question about plugin development + publishing I have a project with 3 subprojects, these 3 subprojects are siblings (let's name it:
    a
    ,
    b
    ,
    c
    ):
    a
    (gradle plugin) that depends on ->
    c
    (core logic)
    b
    (other stuff) that depends on ->
    c
    (core logic) I want to publish gradle plugin with maven with only
    a
    &
    c
    modules in the plugin. But at the same time
    a
    &
    b
    can share the same core logic in the current working project. How can I do that? Is there a sample? Maybe some docs that talk about it? Edit: Not sure if this is the correct place, maybe should I post it in #maven?
    v
    • 2
    • 5
  • r

    Ryan Schmitt

    02/27/2023, 10:20 PM
    Is it an anti-pattern for a plugin to require application to both the
    Settings
    and
    Project
    ?
    v
    m
    • 3
    • 12
  • b

    Ben Madore

    03/03/2023, 10:42 PM
    With the change to Spring 6 / Boot 3 - spring changed their minimum java version to 17 and also modified their gradle plugin, specifically to use Property Providers. I’ve got a conventions plugin that i’d LOVE to be able to use to support Boot2 and Boot3 but i’m struggling to figure out a reasonable way to do it without breaking it out into separate conventions e.g.
    spring-boot2-conventions
    and
    spring-boot3-conventions
    . it needs to support projects that are Spring Boot 2 (Java 11 or Java 17) AND Spring Boot 3 (Java 17 only). the very small difference that causes such a hassle is: boot 2:
    configure<SpringBootExtension> {
    	buildInfo {
    		properties {
    			artifact = extension.artifactName.get()
    			name = extension.projectDisplayName.get()
    			time = null 
    		}
    	}
    }
    boot 3:
    configure<SpringBootExtension> {
    	buildInfo {
    		properties {
    			artifact.set(extension.artifactName.get())
    			name.set(extension.projectDisplayName.get())
    			time.set(null as String?)
    		}
    	}
    }
    v
    e
    v
    • 4
    • 6
  • ł

    Łukasz Wasylkowski

    03/05/2023, 3:44 PM
    Given a task that runs stuff through a work queue in
    processIsolation
    , what's the best practice regarding allowing the consumer to configure
    JavaForkOptions
    of the spawned process? They might want to configure things like available memory, attach daemons etc., while the plugin needs to add some options it knows are needed. Should the task expose entire
    JavaForkOptions
    ? 🤔 Or maybe the task should implement it? Or I should just expose
    jvmArgs
    and maybe other properties similar to what
    JavaForkOptions
    has and pass them manually?
    v
    • 2
    • 6
  • m

    Martin

    03/07/2023, 2:34 PM
    I have a plugin that generates source code. There's a task that outputs a directory so I can nicely get a
    Provider<DirectoryProperty>
    that carries the task dependency using
    task.flatMap { it.outputDir }
    . I want to wire that output to the Kotlin compiler
    main
    source set by default:
    kotlin.sourceSets.getByName("main").kotlin.srcDir(outputDirProperty)
    . All of that while still allowing the user to override that default wiring. Is there a canonical way to do this?
    a
    • 2
    • 29
  • m

    melix

    03/07/2023, 4:17 PM
    hi there! Is there a way to find if a particular feature preview is enabled, without relying on the internal
    FeaturePreviews
    class? In particular I need to determine if the user has enabled Groovy compilation avoidance, because then the project needs to be configured differently.
    p
    • 2
    • 4
  • a

    Adam

    03/08/2023, 9:40 AM
    is there a docs page, or some blog/forum post that explains why Gradle Plugins should be built using Gradle’s embedded Kotlin (via
    kotlin-dsl
    ), and not
    kotlin("jvm") version "x.y.z"
    ?
    j
    e
    +5
    • 8
    • 70
  • r

    Ryan Schmitt

    03/09/2023, 6:44 PM
    Does Gradle have a hook that runs after dependency resolution has finished? I need it for error batching/reporting: I want my plugin to go through all the configurations and report all the errors it finds, instead of short-circuiting on the first bad configuration it finds.
    m
    a
    +2
    • 5
    • 19
  • a

    Adam

    03/10/2023, 9:44 AM
    Is there a standalone example of how to implement Providing multiple variants of a plugin for different Gradle versions? Or is there a helper library or something that helps sets it up? I’m not too concerned with fine-grain control, but a variant per major version would be nice. The Kotlin-GP uses it, but I find it pretty tough to pick through. I’m not clear about what parts are Kotlin-specific. A simpler example would help - does that exist? https://github.com/JetBrains/kotlin/blob/master/buildSrc/src/main/kotlin/gradle-plugin-dependency-configuration.gradle.kts https://github.com/JetBrains/kotlin/blob/master/buildSrc/src/main/kotlin/GradleCommon.kt
    v
    • 2
    • 3
  • j

    Javi

    03/11/2023, 9:18 AM
    If I want to apply a project plugin to all projects via settings plugin, which callback should I use in the settings one?
    v
    • 2
    • 2
  • b

    Benoît

    03/13/2023, 2:32 PM
    How does Gradle understand it has to create some kind of task dependency when we pass folders to some sourceSets’
    srcDir
    ? Does the folder passed has to be annotated with things like
    @get:OutputFile
    for it to work? If yes, how does one pass something like the following to those methods which don’t accept the type
    ConfigurableFileCollection
    ?
    @get:OutputDirectories
      abstract val outputDirectories: ConfigurableFileCollection
    v
    • 2
    • 12
  • a

    Adam

    03/14/2023, 2:55 PM
    I'm using TestKit to test my Gradle plugin. I want to check that it doesn't log to lifecycle during project configuration. The very first time I run my test with args
    clean --no-configuration-cache --no-build-cache
    , I can see in the log output:
    > Configure project :
    > Configure project :subproject-goodbye
    > Configure project :subproject-hello
    > Task :clean
    > Task :subproject-goodbye:clean
    > Task :subproject-hello:clean
    So I can check the
    BuildResult.output
    to verify that it contains this string exactly. But if I re-run the the second time, the test fails because it's missing the
    Configure project
    lines. I've tried deleting the test project's
    .gradle
    directory, but it didn't have any effect. Is there a nice flag I can use to force Gradle to configure all projects?
  • j

    Javi

    03/19/2023, 11:53 PM
    If a plugin uses any file from
    resources
    , should it be possible to test it on Gradle Test Kit? I am getting a null pointer exception, and if I print all resource files it is not there.
    e
    • 2
    • 3
  • d

    Dariusz Kuc

    03/21/2023, 10:31 PM
    hello 👋 I'm writing a custom task that auto generates some additional resource files based on the project main sources - guessing it is a bad idea to just add the generated resource back to the main source (i.e. input and output is the main source)?
Powered by Linen
Title
d

Dariusz Kuc

03/21/2023, 10:31 PM
hello 👋 I'm writing a custom task that auto generates some additional resource files based on the project main sources - guessing it is a bad idea to just add the generated resource back to the main source (i.e. input and output is the main source)?
View count: 1