Using Gradle as file-level annotation instead of a separate build.gradle file

Any ideas on inlining build.gradle into Kotlin code as file-level annotation?

Here is a snippet to get the point: Kotlin Playground: Edit, Run, Share Kotlin Code Online

@file:Build(gradle = """
buildscript {
    repositories {
        mavenCentral()
    }
    
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.3'
    }
}

apply plugin: 'android'

dependencies {
    compile project(':lib')
}

android {
    compileSdkVersion 18
    buildToolsVersion '18.1.0'
}
""")
package app

import kotlin.annotation.AnnotationTarget.FILE

@Target(FILE)
annotation class Build(val gradle: String)

fun main() {
    println("Using Gradle as file-level annotation instead of separate build.gradle file")
}

I don’t think something like this is supported and I don’t see why it should be. What is your use case?

Idea is to have one file for entire project when this project is simple.

1 Like

If I had to do it, I would look for the opposite: embed Kotlin sources inside gradle build file. But it sounds like more problems than profits.

2 Likes

“Simple” Android project in single file - are you joking?

1 Like