Gradle Packaging for production environment and test environment configuration separation
Previous: Maven packaging for production environment and test environment configuration separation
The previous article was package management using Maven, and this time we used Gradle for the configuration of the package management of Java Web Server. Configuring the Gradle configuration file
The directory where the associated resources configuration files are configured in Build.gradle. Different resource files are placed in the src/main/filters/$env directory, where $env directory is the environment name, for example: Dev, test, product, and so on. and defines the default environment for the DEV environment.
def env = System.getproperty ("Profile"): "Dev"
sourcesets {
Main {
resources {
srcdirs = ["src/main/ Resources "," src/main/filters/$env "]}}
}
Put the properties of different environment files, respectively, in the filters directory under the different environment files, as shown below.
When compiling with Gradle, add the parameter-dprofile=dev to specify why the final code of the compilation is the environment. Such as:
# Compile the program into a production environment
./gradlew bootrepackage-dprofile=product
use Intellij idea to launch different Gradle environments
Here's how you can see how MAVEN works in the same way as in the previous article