3

I am building a Spring Boot project and i want to define some constants in gradle. I used to be an Android developer, and in Android you can define it with buildConfigField. How can I do it in Java project?

Is there a tool that is equivalent to the following?

android {
    buildTypes {
        debug {
            buildConfigField "String", "BASE_URL", "http://debug.server.com"
        }
        release {
            buildConfigField "String", "BASE_URL", "http://release.server.com"
        }
    }
}
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Nicholas
  • 479
  • 3
  • 12
  • See https://stackoverflow.com/questions/46805846/how-do-you-specify-buildconfigfield-in-gradle-java-library-project-build-script – mabg Jul 24 '19 at 13:38

1 Answers1

-3

If you are using Gradle as your building tool, you can define Environment Variables inside you build.gradle file, using the following syntax:

buildscript {
    repositories {
        if (System.getenv("RESOLVE_LOCAL")) {
            maven { url "$indexUrl/resolver-grails3" }
        } else {
            maven { url "$indexLocalUrl/resolver-grails3" }
        }
    }

    dependencies {
        classpath 'build-info-extractor:build-info-extractor-gradle:3.1.1'
        classpath group: 'org._10ne.gradle', name: 'rest-gradle-plugin, version: '0.3.1'
    }
}

apply plugin: 'org.10ne.rest'
Rotem
  • 1,381
  • 1
  • 11
  • 23
  • 4
    I don't understand how this answers the question. The question appears to be asking how to vary the value of a Java constant named "BASE_URL." This answer appears to be showing how to vary what Maven repository Gradle uses. – Christopher Simmons Mar 04 '17 at 04:42
  • Environment variables is not the same as compile-time constants. Environment variables may be changed by... well... the environment. – Simon Forsberg Mar 30 '23 at 09:17