Gradle learning labs.
Made with:
- IntelliJ IDEA 2023.1 (Ultimate Edition)
- openjdk 11.0.17
- Gradle 7.6.1
Build the JAR using Gradle
./gradlew clean build
./gradlew clean build -x test
./gradlew clean build testClasses -x test
Add manifest file
jar -cmvf \
./build/tmp/jar/MANIFEST.MF \
./build/libs/gradle-labs-0.0.1-SNAPSHOT.jar \
./build/classes/java/main/org/squidmin/gradlelabs/GradleLabsApplication.class
Build a container image
docker build \
--build-arg GCP_PROJECT_ID=PROJECT_ID \
-t gradle-labs .
Example:
docker build -t \
--build-arg GCP_PROJECT_ID=lofty-root-305785 \
gradle-labs .
Run an interactive container instance
docker run \
--rm -it \
-e GOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
-v $HOME/.config/gcloud:/root/.config/gcloud \
-v $HOME/.m2:/root/.m2 \
gradle-labs
Run the JAR using Gradle
Run the following commands either:
- from the
ENTRYPOINT
in theDockerfile
, or - at the terminal prompt in an interactive container instance.
Use -P=args
to set Gradle project properties.
./gradlew cmdLineJavaExec -Pargs="ARG_1 ARG_2 [...] ARG_N"
Replace the following:
ARG_1 ARG_2 [...] ARG_N
: the values of the arguments expected by the application'smain
method.
Example:
./gradlew cmdLineJavaExec -Pargs="lorem ipsum dolor"
Run the JAR without Gradle
exec java -jar \
-Dspring.profiles.active=local \
-DGOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
./build/libs/spring-rest-labs-0.0.1-SNAPSHOT.jar
Set system properties using -Darg
, where arg
is the argument name.
Pass additional arguments to the application's main
method by placing them after the name of the jar
.
java -Dkey_1=ARG_A -Dkey_2=ARG_B [...] -Dkey_n=ARG_N -jar gradle-labs-0.0.1-SNAPSHOT.jar [ ARG_1 ARG_2 [...] ARG_N ]
Replace the following:
-Dkey_1=ARG_A -Dkey_2=ARG_B [...] -Dkey_n=ARG_N
: the system property keys and values.ARG_1 ARG_2 [...] ARG_N
: the main method arguments.
Example:
java -Dfirst=val_a -Dsecond=val_b -Dspring.profiles.active=local -jar \
gradle-labs-0.0.1-SNAPSHOT.jar arg_1 arg_2 arg_3
Delete the build directory
./gradlew clean
Assemble and test the project
./gradlew build
Assemble the project and skip tests
./gradlew build -x test
or
./gradlew build testClasses -x test
Run the project as a Spring Boot application
./gradlew bootRun
Resolve the name of the application's main class for the bootRun task
./gradlew bootRunMainClassName
Assemble an executable jar archive containing the main classes and their dependencies
./gradlew bootJar
Resolve the name of the application's main class for the bootJar task
./gradlew bootJarMainClassName
Assemble a jar archive containing the main classes
./gradlew jar
Assemble test classes
./gradlew testClasses
Initialize a new Gradle build
./gradlew init
Generate Gradle wrapper files
./gradlew wrapper
List the tasks available
./gradlew tasks
Generate Javadoc API documentation for the main source code
./gradlew javadoc
Display the properties of the root project
./gradlew properties
Display the tasks runnable from the root project
./gradlew tasks
Pass the option --all
to see the tasks in more detail:
./gradlew tasks --all
To see more detail about a task, run:
./gradlew help --task TASK
Replace the following:
TASK
: the name of the task.
Run all checks
./gradlew check
Run the test suite
./gradlew test
Recompile the project and run the test suite
./gradlew clean test
Run a specific test class
./gradlew test --tests TestClassName
Run a specific test method of a specific test class
./gradlew clean test --tests TestClassName.methodName
Run a specific test method of a specific test class, passing command line arguments
./gradlew clean test -Darg_1=example --tests CliArgumentsExampleTest.basicExample
- Gradle Build Scans – insights for your project's build
- Gradle CLI
- Gradle Command Line Arguments
- Java Testing
- Gradle Testing
- JUnit 5 Tutorial: Running Unit Tests with Gradle
- Gradle: How to Run a Single Unit Test Class
- Gradle: How to Show Standard Output or Error Output from Tests
- Gradle Usage with Spring Framework
- Accessing Data with JPA
- Accessing JPA Data with REST
- Building a RESTful Web Service
- Building REST services with Spring