Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/squidmin/gradle-labs
Gradle learning labs
https://github.com/squidmin/gradle-labs
gradle java spring spring-mvc spring-rest
Last synced: 9 days ago
JSON representation
Gradle learning labs
- Host: GitHub
- URL: https://github.com/squidmin/gradle-labs
- Owner: squidmin
- Created: 2023-04-04T13:07:01.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-04-28T01:29:42.000Z (over 1 year ago)
- Last Synced: 2024-10-12T23:01:40.897Z (24 days ago)
- Topics: gradle, java, spring, spring-mvc, spring-rest
- Language: Java
- Homepage:
- Size: 66.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
```shell
./gradlew clean build
``````shell
./gradlew clean build -x test
``````shell
./gradlew clean build testClasses -x test
```Add manifest file
```shell
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
```shell
docker build \
--build-arg GCP_PROJECT_ID=PROJECT_ID \
-t gradle-labs .
```Example:
```shell
docker build -t \
--build-arg GCP_PROJECT_ID=lofty-root-305785 \
gradle-labs .
```## Run the application
Run an interactive container instance
```shell
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.
```shell
./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:
```shell
./gradlew cmdLineJavaExec -Pargs="lorem ipsum dolor"
```Run the JAR without Gradle
### `exec java` command
```shell
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`.
```shell
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:
```shell
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
```shell
./gradlew clean
```Assemble and test the project
```shell
./gradlew build
```Assemble the project and skip tests
```shell
./gradlew build -x test
```or
```shell
./gradlew build testClasses -x test
```Run the project as a Spring Boot application
```shell
./gradlew bootRun
```Resolve the name of the application's main class for the bootRun task
```shell
./gradlew bootRunMainClassName
```Assemble an executable jar archive containing the main classes and their dependencies
```shell
./gradlew bootJar
```Resolve the name of the application's main class for the bootJar task
```shell
./gradlew bootJarMainClassName
```Assemble a jar archive containing the main classes
```shell
./gradlew jar
```Assemble test classes
```shell
./gradlew testClasses
```### Build setup tasks
Initialize a new Gradle build
```shell
./gradlew init
```Generate Gradle wrapper files
```shell
./gradlew wrapper
```### Application tasks
List the tasks available
```shell
./gradlew tasks
```### Documentation tasks
Generate Javadoc API documentation for the main source code
```shell
./gradlew javadoc
```#### Help tasks
Display the properties of the root project
```shell
./gradlew properties
```Display the tasks runnable from the root project
```shell
./gradlew tasks
```Pass the option `--all` to see the tasks in more detail:
```shell
./gradlew tasks --all
```To see more detail about a task, run:
```shell
./gradlew help --task TASK
```**Replace the following**:
- `TASK`: the name of the task.### Verification tasks
Run all checks
```shell
./gradlew check
```Run the test suite
```shell
./gradlew test
```Recompile the project and run the test suite
```shell
./gradlew clean test
```Run a specific test class
```shell
./gradlew test --tests TestClassName
```Run a specific test method of a specific test class
```shell
./gradlew clean test --tests TestClassName.methodName
```Run a specific test method of a specific test class, passing command line arguments
```shell
./gradlew clean test -Darg_1=example --tests CliArgumentsExampleTest.basicExample
```---
## Guides
### Gradle
* [Gradle Build Scans – insights for your project's build](https://scans.gradle.com#gradle)
* [Gradle CLI](https://docs.gradle.org/current/userguide/command_line_interface.html)
* [Gradle Command Line Arguments](https://www.baeldung.com/gradle-command-line-arguments)
* [Java Testing](https://docs.gradle.org/current/userguide/java_testing.html)
* [Gradle Testing](https://www.tutorialspoint.com/gradle/gradle_testing.htm)
* [JUnit 5 Tutorial: Running Unit Tests with Gradle](https://www.petrikainulainen.net/programming/testing/junit-5-tutorial-running-unit-tests-with-gradle/)
* [Gradle: How to Run a Single Unit Test Class](https://mkyong.com/gradle/gradle-how-to-run-a-single-unit-test-class/)
* [Gradle: How to Show Standard Output or Error Output from Tests](https://blog.mrhaki.com/2014/10/gradle-goodness-show-standard-out-or.html)
* [Gradle Usage with Spring Framework](https://spring.io/guides/gs/gradle/#scratch)### Spring
* [Accessing Data with JPA](https://spring.io/guides/gs/accessing-data-jpa/)
* [Accessing JPA Data with REST](https://spring.io/guides/gs/accessing-data-rest/)
* [Building a RESTful Web Service](https://spring.io/guides/gs/rest-service/)
* [Building REST services with Spring](https://spring.io/guides/tutorials/rest/)---
### Other references
* [Official Gradle documentation](https://docs.gradle.org)
* [Spring Boot Gradle Plugin Reference Guide](https://docs.spring.io/spring-boot/docs/2.7.10/gradle-plugin/reference/html/)
* [Create an OCI image](https://docs.spring.io/spring-boot/docs/2.7.10/gradle-plugin/reference/html/#build-image)
* [Spring Configuration Processor](https://docs.spring.io/spring-boot/docs/2.7.10/reference/htmlsingle/#appendix.configuration-metadata.annotation-processor)
* [Rest Repositories](https://docs.spring.io/spring-boot/docs/2.7.10/reference/htmlsingle/#howto.data-access.exposing-spring-data-repositories-as-rest)
* [Spring Web](https://docs.spring.io/spring-boot/docs/2.7.10/reference/htmlsingle/#web)