Skip to content

squidmin/gradle-labs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gradle-labs

Gradle learning labs.

Made with:

  • IntelliJ IDEA 2023.1 (Ultimate Edition)
  • openjdk 11.0.17
  • Gradle 7.6.1

Install & build

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 the application

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 the Dockerfile, 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's main method.

Example:

./gradlew cmdLineJavaExec -Pargs="lorem ipsum dolor"
Run the JAR without Gradle

exec java command

exec java -jar \
  -Dspring.profiles.active=local \
  -DGOOGLE_APPLICATION_CREDENTIALS=$GOOGLE_APPLICATION_CREDENTIALS \
  ./build/libs/spring-rest-labs-0.0.1-SNAPSHOT.jar

java command

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

Tasks

Build tasks

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

Build setup tasks

Initialize a new Gradle build
./gradlew init
Generate Gradle wrapper files
./gradlew wrapper

Application tasks

List the tasks available
./gradlew tasks

Documentation tasks

Generate Javadoc API documentation for the main source code
./gradlew javadoc

Help tasks

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.

Verification tasks

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

Guides

Gradle

Spring


Other references