-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 3aee2e8
Showing
22 changed files
with
728 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: build | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- .github/workflows/cancel.yml | ||
- .github/workflows/codeql.yml | ||
- .github/workflows/release.yml | ||
- .gitignore | ||
- gradle.properties | ||
- LICENSE | ||
- README.md | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
uses: opengoodio/central-workflows/.github/workflows/gradle-lib-build.yml@main | ||
with: | ||
run-gradle-validation: true | ||
secrets: | ||
fossa-api-key: ${{ secrets.FOSSA_API_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: cancel | ||
on: [push] | ||
|
||
jobs: | ||
cancel: | ||
uses: opengoodio/central-workflows/.github/workflows/workflow-cancel.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CodeQL | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths-ignore: | ||
- .github/workflows/cancel.yml | ||
- .github/workflows/codeql.yml | ||
- .github/workflows/release.yml | ||
- .gitignore | ||
- gradle.properties | ||
- LICENSE | ||
- README.md | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
uses: opengoodio/central-workflows/.github/workflows/codeql-analyze.yml@main | ||
with: | ||
java-version: 17 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: release | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
release: | ||
uses: opengoodio/central-workflows/.github/workflows/gradle-oss-release.yml@main | ||
with: | ||
git-email: ${{ vars.GIT_EMAIL }} | ||
git-user: ${{ vars.GIT_USER }} | ||
run-gradle-validation: true | ||
secrets: | ||
gpg-signing-password: ${{ secrets.GPG_SIGNING_PASSWORD }} | ||
gpg-signing-private-key: ${{ secrets.GPG_SIGNING_PRIVATE_KEY }} | ||
oss-repo-username: ${{ secrets.OSS_REPO_USERNAME }} | ||
oss-repo-password: ${{ secrets.OSS_REPO_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
### macOS ### | ||
.DS_Store | ||
|
||
### IntelliJ IDEA ### | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.idea | ||
generated/ | ||
generated_tests/ | ||
out/ | ||
|
||
### Gradle ### | ||
!gradle/wrapper/gradle-wrapper.jar | ||
.gradle | ||
build/ | ||
|
||
### GitHub Actions ### | ||
\~/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2020-2023 OpenGood | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# Spring Commons Library | ||
|
||
[![Build](https://github.com/opengoodio/spring-constants/workflows/build/badge.svg)](https://github.com/opengoodio/spring-constants/actions?query=workflow%3Abuild) | ||
[![Release](https://github.com/opengoodio/spring-constants/workflows/release/badge.svg)](https://github.com/opengoodio/spring-constants/actions?query=workflow%3Arelease) | ||
[![CodeQL](https://github.com/opengoodio/spring-constants/actions/workflows/codeql.yml/badge.svg)](https://github.com/opengoodio/spring-constants/actions/workflows/codeql.yml) | ||
[![Codecov](https://codecov.io/gh/opengoodio/spring-constants/branch/main/graph/badge.svg?token=AEEYTGK87F)](https://codecov.io/gh/opengoodio/spring-constants) | ||
[![Release Version](https://img.shields.io/github/release/opengoodio/spring-constants.svg)](https://github.com/opengoodio/spring-constants/releases/latest) | ||
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.opengood.constants/spring-constants/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.opengood.constants/spring-constants) | ||
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/opengoodio/spring-constants/master/LICENSE) | ||
[![FOSSA](https://app.fossa.com/api/projects/custom%2B22161%2Fgit.luolix.top%2Fopengoodio%2Fspring-constants.svg?type=small)](https://app.fossa.com/projects/custom%2B22161%2Fgit.luolix.top%2Fopengoodio%2Fspring-constants?ref=badge_small) | ||
|
||
Library containing reusable constants for Spring and Spring Boot | ||
|
||
## Compatibility | ||
|
||
* Java 17 | ||
* Spring Boot 3 | ||
|
||
## Setup | ||
|
||
### Add Dependency | ||
|
||
#### Gradle | ||
|
||
```groovy | ||
implementation("io.opengood.constants:spring-constants:VERSION") | ||
``` | ||
|
||
#### Maven | ||
|
||
```xml | ||
|
||
<dependency> | ||
<groupId>io.opengood.constants</groupId> | ||
<artifactId>spring-constants</artifactId> | ||
<version>VERSION</version> | ||
</dependency> | ||
``` | ||
|
||
**Note:** See *Release* version badge above for latest version. | ||
|
||
## Features | ||
|
||
**Note:** All examples are provided in Kotlin | ||
|
||
### Reusable Spring Properties | ||
|
||
Common Spring properties are often referenced in code for importing | ||
configuration values. Rather than defining these constantly, simply refer to | ||
them as constants. | ||
|
||
| Constant | Spring Property | | ||
|------------------------------------------|--------------------------------| | ||
| `SpringProperties.APPLICATION_NAME` | `spring.application.name` | | ||
| `SpringProperties.DATA_MONGODB_DATABASE` | `spring.data.mongodb.database` | | ||
| `SpringProperties.DATA_MONGODB_HOST` | `spring.data.mongodb.host` | | ||
| `SpringProperties.DATA_MONGODB_PASSWORD` | `spring.data.mongodb.password` | | ||
| `SpringProperties.DATA_MONGODB_PORT` | `spring.data.mongodb.port` | | ||
| `SpringProperties.DATA_MONGODB_URI` | `spring.data.mongodb.uri` | | ||
| `SpringProperties.DATA_MONGODB_USERNAME` | `spring.data.mongodb.username` | | ||
|
||
--- | ||
|
||
### Reusable Spring Property Placeholders | ||
|
||
Similarly, when using `@Value` to import Spring property values, one needs to | ||
wrap `${}` around the property. These are also provided as constants one can | ||
simply refer. | ||
|
||
| Constant | Spring Property Placeholder | | ||
|----------------------------------------------------|-----------------------------------| | ||
| `SpringPropertyPlaceholders.APPLICATION_NAME` | `${spring.application.name}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_DATABASE` | `${spring.data.mongodb.database}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_HOST` | `${spring.data.mongodb.host}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_PASSWORD` | `${spring.data.mongodb.password}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_PORT` | `${spring.data.mongodb.port}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_URI` | `${spring.data.mongodb.uri}` | | ||
| `SpringPropertyPlaceholders.DATA_MONGODB_USERNAME` | `${spring.data.mongodb.username}` | | ||
|
||
Example: | ||
|
||
```kotlin | ||
import io.opengood.constants.spring.SpringPropertyPlaceholders | ||
|
||
@Configuration | ||
class AppConfig { | ||
|
||
@Bean | ||
fun bean(@Value(SpringPropertyPlaceholders.APPLICATION_NAME) value: String): String { | ||
// configure bean | ||
} | ||
} | ||
``` | ||
|
||
--- | ||
|
||
### Reusable Spring Property Settings | ||
|
||
Sometimes one needs to use defined Spring property settings and remembering a | ||
specific property is hard. Constants are provided to simplify this: | ||
|
||
| Constant | Spring Property Setting | | ||
|---------------------------------------------------|-----------------------------------------------------| | ||
| `SpringPropertySettings.BEAN_DEFINITION_OVERRIDE` | `spring.main.allow-bean-definition-overriding=true` | | ||
|
||
Example: | ||
|
||
```kotlin | ||
import io.opengood.constants.spring.SpringPropertySettings | ||
|
||
@SpringBootTest( | ||
classes = [TestApplication::class], | ||
properties = [SpringPropertySettings.BEAN_DEFINITION_OVERRIDE], | ||
webEnvironment = WebEnvironment.RANDOM_PORT | ||
) | ||
class ControllerTest : WordSpec() { | ||
// do stuff | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
plugins { | ||
id("io.opengood.gradle.config") | ||
} | ||
|
||
group = "io.opengood.constants" | ||
|
||
opengood { | ||
artifact { | ||
description = "Library containing reusable constants for Spring and Spring Boot" | ||
} | ||
features { | ||
assertj = false | ||
jackson = false | ||
jacksonKotlin = false | ||
junitJupiter = false | ||
kotest = true | ||
kotestSpring = false | ||
kotlinCoroutines = false | ||
lombok = false | ||
mockito = false | ||
mockk = false | ||
spring = false | ||
springMockk = false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version=3.5.0-SNAPSHOT |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.