-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
0e154bf
commit 3fbb763
Showing
4 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
build-logic/jvm/src/main/kotlin/build-logic.build-info.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import buildlogic.BuildInfoTask | ||
|
||
plugins { | ||
java | ||
} | ||
|
||
val generateBuildInfo by tasks.registering(BuildInfoTask::class) { | ||
version.set(project.version.toString()) | ||
genDir.set(project.layout.buildDirectory.dir("generated/buildinfo")) | ||
} | ||
|
||
sourceSets.main { | ||
java.srcDir(generateBuildInfo) | ||
} |
37 changes: 37 additions & 0 deletions
37
build-logic/jvm/src/main/kotlin/buildlogic/BuildInfoTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package buildlogic | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.DirectoryProperty | ||
import org.gradle.api.file.RegularFile | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.provider.Provider | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.InputDirectory | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.OutputFile | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
abstract class BuildInfoTask : DefaultTask() { | ||
@get:Input | ||
abstract val packageName: Property<String> | ||
|
||
@get:Input | ||
abstract val version: Property<String> | ||
|
||
@get:OutputDirectory | ||
abstract val genDir: DirectoryProperty | ||
|
||
@TaskAction | ||
fun run() { | ||
val output = """ | ||
|package ${packageName.get()}; | ||
| | ||
|public class BuildInfo { | ||
| public static final String VERSION = "${version.get()}"; | ||
|} | ||
""".trimMargin() | ||
val outputPath = genDir.file(packageName.get().replace(".", "/").plus("/BuildInfo.java")).get().asFile | ||
outputPath.parentFile.mkdirs() | ||
outputPath.writeText(output) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters