如何从www.example.com获取值gradle.properties到Kotlin文件中?

rjzwgtxy  于 2023-02-09  发布在  Kotlin
关注(0)|答案(1)|浏览(132)

这个常数的单位是gradle.properties

VERSION_NAME=0.1.0

我希望能够在我的Kotlin文件(一个数据类)中使用这个值。类似于尝试从System.getProperty("VERSION_NAME")中提取它。
这是数据类所在模块上的build.gradle.kts(KotlinDSL

plugins {
    id("java-library")
    id("org.jetbrains.kotlin.jvm")
    id("com.vanniktech.maven.publish")
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

dependencies {
    implementation(Dependencies.Squareup.Retrofit2.retrofit)
    implementation(Dependencies.Squareup.Retrofit2.converterGson)
    implementation(Dependencies.Squareup.Okhttp3.okhttp)
    implementation(Dependencies.Squareup.Okhttp3.loggingInterceptor)
    implementation(Dependencies.Google.Code.gson)
}

我对Android比较熟悉,你在那里有一个BuildConfig静态常量,但是因为这不是一个Android项目,我需要以不同的方式获得这个值。
我尝试按照How do I get a custom property defined in 'gradle.properties in kotlin code?,这是非常类似于我需要的,除了tasks.named<JavaExec>("run")...不会工作,因为“运行”任务是在项目中找不到。
我是新的这些类型的Kotlin项目和gradle一般,所以我迷路了。

相关问题