Skip to content

Commit

Permalink
Merge pull request #82 from Ensono/fix/deps
Browse files Browse the repository at this point in the history
feat: migration to new namespace and package upgrades
  • Loading branch information
ElvenSpellmaker authored Oct 9, 2024
2 parents 4ab6e60 + 304ee5c commit e4a6a73
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 294 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

.gradle

gpg_private_key.asc

settings.xml

java/target/
api-tests/target
java/build/
Expand Down
22 changes: 0 additions & 22 deletions .mvn/settings.xml

This file was deleted.

121 changes: 3 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,22 @@ deploy.

```
java
\_.mvn
: |_settings.xml
|_archetype.properties
|_pom.xml
```

## How to use

There are four ways to integrate this module into your project:

- Use it as a [dependency](#use-it-as-a-dependency)
- Create a localized solution using [Maven Archetypes artifacts](#localized-solution-using-maven-archetypes) available in our Artifactory repo
- Clone this repo, [locally build](#building-the-module-locally-from-this-repository) and use it as a Maven dependency
- Clone this repo, create a [custom archetype](#creating-an-archetype-from-this-repository) and then use it as a Maven dependency

### Use it as a dependency
Use it as a dependency.

#### Maven

In the `parent` section of your application's `pom.xml` add:

```xml
<dependency>
<groupId>com.amido.stacks.modules</groupId>
<groupId>com.ensono.stacks.modules</groupId>
<artifactId>stacks-modules-parent</artifactId>
<version>1.0.1-RC5</version>
<version>1.0.1</version>
<type>pom</type>
</dependency>
```
Expand All @@ -54,115 +44,10 @@ Then you can do a `./mvnw clean compile` to fetch it; after that, you can use it
./mvnw clean compile
```

#### Others

Use it as you'd use any dependency in your build tool.

### Localized solution using Maven Archetypes

If you wish to customise the module and use your organisation's namespaces instead of Ensono's, you can create a
[Maven archetype](https://maven.apache.org/archetype/index.html). Archetypes are Maven's tool for
scaffolding and offers lots of extra functionality. We suggest spending some time looking into them.
We use Archetype to create a template and enable you to adopt this module under your organisation's namespace.
To use the deployed archetypes:

1. Make and move to a new folder
2. Then run

``` bash
mvn archetype:generate \
-DarchetypeGroupId='com.amido.stacks.modules' \
-DarchetypeArtifactId='stacks-modules-parent-archetype' \
-DarchetypeVersion='<archetype version>' \
-DgroupId='<your-group-id>' \
-DartifactId='<your-artifact-id>' \
-Dversion='<your-version>' \
-Dpackage='<package-name>'
```

- `<your-group-id>` is a placeholder for your group ID
- `<your-artifact-id>` is a placeholder for your artefact ID
- `<your-version>` is a placeholder for your version
- `<package-name>` is a placeholder for the root package name and structure. It should start with your `groupdId` and continue with the name of the root package.

> For example, using `-DgroupId=com.test` and `-Dpackage=com.test.stacks` will instruct Maven to place the code in `src/main/java/com/test/stacks` and update all the relevant references accordingly (i.e. `imports`)

3. Go to the `pom.xml` file of the project you'll be using this module in and add it as a [dependency](#use-it-as-a-dependency)
> **If you previously had used this module under different namespace (i.e. the default `com.amido.stacks.core-api`):**
>
> Maven ONLY updates the imports for the module you generated. Any references in other projects will remain to the previous namespace.
>
> You will need to
>
>- Update them manually
>- Re-create the relevant `import` statements to use the new-made module instead
>- If you plan to use this with Ensono Stacks, include your namespace in the `@ComponentScan` annotation of the `Application` class.
### Building the module locally from this repository

To build the module locally:

1. Clone this repo
3. run `./mvnw clean install` to install the module locally.
4. Add it as any other [dependency](#use-it-as-a-dependency)
### Creating an Archetype from this repository
If you wish to customise the module and use your organisation's namespaces instead of Ensono's. You can create a
[Maven archetype](https://maven.apache.org/archetype/index.html). Archetype is Maven's tool for
scaffolding and offers lots of extra functionality. We suggest spending some time looking into them. We use Archetype to create a template and enable you to adopt this module under your organisation's namespace.
To use the deployed archetypes:
To build, install and use the archetype follow these steps:
1. Clone this repo
2. Navigate to the `<directory you cloned the project into>` in the terminal
3. Then issue the following Maven commands, using the included wrapper:
1. Create the archetype from the existing code
```bash
./mvnw archetype:create-from-project -DpropertyFile='./archetype.properties'
```
2. Navigate to the folder it was created in
```bash
cd target/generated-sources/archetype
```
3. Install the archetype locally
```bash
..\..\..\mvnw install
```
4. Make and navigate to a directory in which you'd like to create the localized project, ideally outside this project's root folder
5. To create the project, use the command below:
```bash
<path-to-mvn-executable>/mvnw archetype:generate \
-DarchetypeGroupId='com.amido' \
-DarchetypeArtifactId='stacks-modules-parent-archetype' \
-DarchetypeVersion='<VERSION>' \
-DgroupId='<your-group-id>' \
-DartifactId='<your-artifact-id>' \
-Dversion='<your-version>' \
-Dpackage='<package-name>'`
```
1. `<your-group-id>` is a placeholder for your group ID
2. `<your-artifact-id>` is a placeholder for your artefact ID
3. `<your-version>` is a placeholder for your version
4. `<package-name>` is a placeholder for the root package name and structure. It should start with your `groupdId` and continue with the name of the root package.
> For example, using `-DgroupId=com.test` and `-Dpackage=com.test.stacks` will instruct Maven to place the code in `src/main/java/com/test/stacks` and update all the relevant references accordingly (i.e. `imports`)
6. Go to the `pom.xml` file of the project you'll be using this module in and add it as a [dependency](#use-it-as-a-dependency)

> **If you previously had used this module under different namespace (i.e. the default `com.amido.stacks.core-api`):**
>
> Maven ONLY updates the imports for the module you generated. Any references in other projects will remain to the previous namespace.
>
> You will need to
>
>- Update them manually
>- Re-create the relevant `import` statements to use the new-made module instead
>- If you plan to use this with Ensono Stacks, include your namespace in the `@ComponentScan` annotation of the `Application` class.
2 changes: 0 additions & 2 deletions archetype.properties

This file was deleted.

90 changes: 31 additions & 59 deletions build/azDevOps/azure/azure-pipelines-javaspring-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# NB: Some resources e.g. blob storage only allow for alpha numeric characters so the name is adjusted accordingly #
# ==> `$company$project$stage$domain` #
#############################################################################################################################
name: $(version_major).$(version_minor).$(Rev:r)-$(build_type)
name: $(version_major).$(version_minor).$(Rev:r)$(build_type)

pr:
- main
Expand Down Expand Up @@ -36,10 +36,10 @@ resources:
# Container for Java Build and Testing
# Container for Sonar Scanner
- container: azul_java
image: ensono/eir-java:1.1.251
image: ensono/eir-java:1.1.257
# Container for Kubernetes Deployment
- container: k8s_deploy
image: ensono/eir-infrastructure:1.1.251
image: ensono/eir-infrastructure:1.1.257

variables:
- template: azuredevops-vars.yml
Expand All @@ -52,6 +52,8 @@ stages:
- group: sonar-credentials
- group: stacks-java-modules
- group: stacks-java-module-parent
- group: maven-credentials
- group: release-github-credentials
jobs:
- job: ModuleBuild
pool:
Expand All @@ -70,7 +72,7 @@ stages:
yamllint_config_file: "${{ variables.yamllint_config_file }}"
yamllint_scan_directory: "${{ variables.yamllint_scan_directory }}"

# Builds the Java app, runs tests and deploy to the artifact repository
# Builds the Java app and runs tests
- template: azDevOps/azure/templates/steps/java/build-java.yml@templates
parameters:
repo_root_dir: "${{ variables.self_repo_dir }}"
Expand All @@ -79,25 +81,18 @@ stages:
# Maven
maven_cache_directory: "${{ variables.maven_cache_directory }}"
maven_surefire_reports_dir: "${{ variables.maven_surefire_reports_dir }}"
maven_allowed_test_tags: "${{ variables.maven_allowed_test_tags}}"
maven_allowed_test_tags: "${{ variables.maven_allowed_test_tags }}"
maven_package_version: "${{ variables.maven_package_version }}"
maven_settings_file: "${{ variables.maven_settings_file }}"
# OSSRH
ossrh_jira_id: "$(ossrh-jira-id)"
ossrh_jira_password: "$(ossrh-jira-password)"
# Docker
docker_build_container: "${{ variables.docker_java_image }}"
# Vulnerability Scanning
vulnerability_scan: "${{ variables.vulnerability_scan }}"
vulnerability_scan_fail_build_on_detection: "${{ variables.vulnerability_scan_fail_build_on_detection }}"
vulnerability_scan_report: "${{ variables.vulnerability_scan_report }}"
vulnerability_scan_api_key: ${{ variables.vulnerability_scan_api_key }}
vulnerability_scan_database_directory: ${{ variables.vulnerability_scan_database_directory }}
project_type: "${{ variables.java_project_type }}"
build_type: "${{ variables.build_type }}"
# private key id to sign doc
gpg_key_signing_id: "$(gpg-key-signing-id)"
gpg_private_key: "$(gpg-private-key)"
vulnerability_scan_report: "${{ variables.vulnerability_scan_report }}"

# Performs static code analysis, such as Sonar Cloud
- template: azDevOps/azure/templates/steps/java/test-static-code-analysis.yml@templates
Expand All @@ -122,6 +117,27 @@ stages:
# Docker
docker_image_tag: "${{ variables.docker_image_tag }}"

# Deploy to the Maven Repository
- template: azDevOps/azure/templates/steps/java/deploy-java.yml@templates
parameters:
repo_root_dir: "${{ variables.self_repo_dir }}"
project_root_dir: "${{ variables.self_project_dir }}"
pom_dir: "${{ variables.self_project_dir }}"
pipeline_scripts_directory: "${{ variables.self_pipeline_scripts_dir }}"
# Docker
docker_build_container: "${{ variables.docker_java_image }}"
# Project
project_type: "${{ variables.java_project_type }}"
build_type: "${{ variables.build_type }}"
# MAVEN CENTRAL
maven_id: "$(MAVEN_ID)"
maven_username: "$(MAVEN_USERNAME)"
maven_password: "$(MAVEN_PASSWORD)"
maven_package_version: "${{ variables.maven_package_version }}"
# private key id to sign doc
gpg_key_signing_id: "$(gpg-key-signing-id)"
gpg_private_key: "$(gpg-private-key)"

# Post build tasks, such as Test and Coverage upload, and publishing artefacts
- template: azDevOps/azure/templates/steps/java/post-build-tasks.yml@templates
parameters:
Expand All @@ -144,53 +160,9 @@ stages:
# Docker
docker_build_container: "${{ variables.docker_java_image }}"

- job: ArchetypeBuild
dependsOn: ModuleBuild
pool:
vmImage: $(pool_vm_image)
variables:
- group: release-github-credentials
steps:
- checkout: self

- checkout: templates

# Validates all YAML files in the repo to check they adhere to standards
- template: azDevOps/azure/templates/steps/java/test-validate-yaml.yml@templates
parameters:
pipeline_scripts_directory: "${{ variables.self_pipeline_scripts_dir }}"
container: "k8s_deploy"
yamllint_config_file: "${{ variables.yamllint_config_file }}"
yamllint_scan_directory: "${{ variables.yamllint_scan_directory }}"

# Builds the Java archetype and deploy to the artifact repository
- template: azDevOps/azure/templates/steps/java/build-java-archetype.yml@templates
parameters:
repo_root_dir: "${{ variables.self_repo_dir }}"
project_root_dir: "${{ variables.self_project_dir }}"
pipeline_scripts_directory: "${{ variables.self_pipeline_scripts_dir }}"
# Maven
maven_cache_directory: "${{ variables.maven_cache_directory }}"
maven_surefire_reports_dir: "${{ variables.maven_surefire_reports_dir }}"
maven_allowed_test_tags: "${{ variables.maven_allowed_test_tags}}"
maven_package_version: "${{ variables.maven_package_version }}"
maven_pom_file: "${{ variables.maven_archetype_pom_file }}"
maven_archetype_properties_file: "${{ variables.maven_archetype_properties_file }}"
maven_settings_file: "${{ variables.maven_settings_file }}"
maven_repository_server: "${{ variables.maven_repository_server }}"
# OSSRH
ossrh_jira_id: "$(ossrh-jira-id)"
ossrh_jira_password: "$(ossrh-jira-password)"
# Docker
docker_build_container: "${{ variables.docker_java_image }}"
project_type: "${{ variables.java_project_type }}"
build_type: "${{ variables.build_type }}"
# private key id to sign doc
gpg_private_key: "$(gpg-private-key)"
gpg_key_signing_id: "$(gpg-key-signing-id)"

# Release
- task: PowerShell@2
condition: eq(variables['build_type'], 'RELEASE')
condition: eq(variables['build_type'], '')
inputs:
targetType: inline
script: |
Expand Down
15 changes: 2 additions & 13 deletions build/azDevOps/azure/azuredevops-vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ variables:
value: 0
- name: build_type
${{ if eq( variables['Build.SourceBranchName'], 'main' ) }}:
value: "RELEASE"
value: ""
${{ else }}:
value: "SNAPSHOT"
value: "-PR"

# PR / Branch vars
- name: source_branch_ref
Expand Down Expand Up @@ -93,17 +93,6 @@ variables:
value: "target/surefire-reports"
- name: maven_allowed_test_tags
value: "Unit | Component | Integration"
- name: maven_archetype_pom_file
value: "target/generated-sources/archetype/pom.xml"
- name: maven_archetype_properties_file
value: "archetype.properties"
- name: maven_settings_file
value: "./.mvn/settings.xml"
- name: maven_repository_server
${{ if eq( variables['Build.SourceBranchName'], 'main' ) }}:
value: ossrh::https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/
${{ if ne( variables['Build.SourceBranchName'], 'main' ) }}:
value: ossrh::https://s01.oss.sonatype.org/content/repositories/snapshots

# Vulnerability Scan
- name: vulnerability_scan
Expand Down
Loading

0 comments on commit e4a6a73

Please sign in to comment.