Skip to content

Repository files navigation

Setupapp gradle plugin

Adds resources from dependent gradle modules to the target jar file with filtering environment folders (also supports jsMain target).

Setup

  • Kotlin DSL:
plugins {
id("ru.raysmith.setupapp") version "2.3"
}
  • Groovy:
plugins {
id 'ru.raysmith.setupapp' version '2.3'
}
  • With TOML:
[plugins]
setupapp = { id = "ru.raysmith.setupapp", version = "2.3" }
@Suppress("DSL_SCOPE_VIOLATION")
plugins {
alias(libs.plugins.setupapp)
}

Usage

Let's imagine that we want to inheritance all resources from dependent modules in this project:

project
├── app
│ ├── src
│ │ └── main
│ │ ├── kotlin
│ │ └── resources
│ │ └── index.html
│ └── app.gradle.kts
├── submodule-a
│ ├── src
│ │ └── main
│ │ ├── kotlin
│ │ └── resources
│ │ ├── somefile.txt
│ │ ├── dev
│ │ │ └── foo.properties
│ │ ├── prod
│ │ │ └── bar.properties
│ │ └── folder
│ │ └── doc.pdf
│ └── submodule-a.gradle.kts
├── submodule-b
│ ├── src
│ │ └── main
│ │ ├── kotlin
│ │ └── resources
│ │ └── image.jpg
│ └── submodule-b.gradle.kts
├── submodule-c
│ ├── src
│ │ └── main
│ │ ├── kotlin
│ │ └── resources
│ │ ├── dev
│ │ │ └── secret.json
│ │ └── prod
│ │ └── secret.json
│ └── submodule-c.gradle.kts
└── build.gradle.kts
graph LR;
A(app) --> sa & sb;
sa(submodule-a);
sb(submodule-b) ---> sc;
sc(submodule-c);
Loading

In app.gradle.kts:

setupapp {
}

After creating the JAR file with gradle :app:shadowJar -Denv=dev, its structure is:

app.jar
├── index.html
├── somefile.txt
├── foo.properties
├── folder/doc.pdf
├── image.jpg
└── secret.json (from dev)

Don't forget run gradle :app:clean after change env

Configuration

You don't need to configure any properties if you are using only the dev and prod environments. In other cases there are properties:

nametypedefaultdescription
envStringdevCurrent environment
envsSet[dev, prod]Set of all environments
prodBooleanenv == 'prod'If it is true plugin will be used output from jsBrowserProductionWebpack for modules with jsMain targets
sourceSetsSet[main, commonMain, jvmMain]List of sourceSet from which resources should be inherited

Example

setupapp {
env.set(env())
envs.set(setOf("dev", "prod", "sandbox"))
prod.set(env() =="prod")
sourceSets.set(setOf("commonMain", "jvmMain", "jsMain"))
}

About

Gradle application's resources resolver plugin

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages