admin管理员组

文章数量:1335127

I have a gradle task which generates a json file containing all libraries used in my Kotlin Multiplatform Application. The output file will be parsed, and rendered in the UI.

./gradlew features:about:exportLibraryDefinitions - PaboutLibraries.exportPath=src/commonMain/composeResources/files -PaboutLibraries.exportVariant=release

Now, this task is quite long to type, and it requires the exact exportPath to be the same as the one that my file reader expects. Therefor, I would like to wrap it in another gradle (simpler) task:

tasks updateLicenseInformation = tasks.register("updateLicenseInformation"){
   group = "Entreco"
   description = "Update all license information json file"
   
   // How to execute 
   //"gradle features:about:exportLibraryDefinitions - PaboutLibraries.exportPath=src/commonMain/composeResources/files -PaboutLibraries.exportVariant=release" 
   // here?
} 

How can I execute my gradle command here? I am using Android Studio + Gradle with Kotlin

I have a gradle task which generates a json file containing all libraries used in my Kotlin Multiplatform Application. The output file will be parsed, and rendered in the UI.

./gradlew features:about:exportLibraryDefinitions - PaboutLibraries.exportPath=src/commonMain/composeResources/files -PaboutLibraries.exportVariant=release

Now, this task is quite long to type, and it requires the exact exportPath to be the same as the one that my file reader expects. Therefor, I would like to wrap it in another gradle (simpler) task:

tasks updateLicenseInformation = tasks.register("updateLicenseInformation"){
   group = "Entreco"
   description = "Update all license information json file"
   
   // How to execute 
   //"gradle features:about:exportLibraryDefinitions - PaboutLibraries.exportPath=src/commonMain/composeResources/files -PaboutLibraries.exportVariant=release" 
   // here?
} 

How can I execute my gradle command here? I am using Android Studio + Gradle with Kotlin

Share Improve this question asked Nov 20, 2024 at 15:20 EntrecoEntreco 12.9k8 gold badges78 silver badges98 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I expect the below to work.

However it is not guaranteed because there appears to be a bug setting project properties in Kotlin build scripts and accessing them in other build scripts which I encountered in testing. I have logged this as a Gradle issue with a reproducible project so we can see what the Gradle team say.

tasks.register("updateLicenseInformation"){
   group = "Entreco"
   description = "Update all license information json file"
   extra["aboutLibraries.exportPath"] = "src/commonMain/composeResources/files"
   extra["aboutLibraries.exportVariant"] = "release"
   /**
    * The following, setting properties on the "ext" object, should not be necessary
    * per the documentation, but in testing the properties were not
    * accessible by Groovy scripts without these
    * See https://docs.gradle./current/userguide/migrating_from_groovy_to_kotlin_dsl.html
    */
   ext["aboutLibraries.exportPath"] = "src/commonMain/composeResources/files"
   ext["aboutLibraries.exportVariant"] = "release"
   dependsOn("features:about:exportLibraryDefinitions")
} 

本文标签: androidWrap a gradle task in a simpler oneStack Overflow