From a8b8404b3ef5d1cf34301663d6b6effb2294a7e3 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sat, 20 May 2023 17:11:52 +0200 Subject: [PATCH 01/22] first version of the two main archetypes --- .github/workflows/ci.yml | 11 + .gitignore | 48 +++ README.md | 368 ++++++++++++++++++ dependency-version.properties | 1 + maven-archetype-simple/pom.xml | 25 ++ .../archetype-resources/pom.xml | 83 ++++ .../META-INF/maven/archetype-metadata.xml | 20 + .../archetype-resources/.mvn/jvm.config | 0 .../archetype-resources/.mvn/maven.config | 0 .../src/main/java/App.java | 13 + .../archetype-resources/src/site/site.xml | 26 ++ .../src/test/java/AppTest.java | 21 + .../src/site/markdown/README.md.vm | 54 +++ maven-archetype-simple/src/site/site.xml | 8 + .../projects/it-basic/archetype.properties | 4 + .../test/resources/projects/it-basic/goal.txt | 1 + maven-archetype-withparent | 1 + plugin-versions.properties | 17 + pom.xml | 91 +++++ rules.xml | 16 + src/site/site.xml | 41 ++ src/site/xdoc/download.xml.vm | 126 ++++++ 22 files changed, 975 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 README.md create mode 100644 dependency-version.properties create mode 100644 maven-archetype-simple/pom.xml create mode 100644 maven-archetype-simple/src/main/resources-filtered/archetype-resources/pom.xml create mode 100644 maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/.mvn/jvm.config create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/.mvn/maven.config create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/src/main/java/App.java create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/src/site/site.xml create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java create mode 100644 maven-archetype-simple/src/site/markdown/README.md.vm create mode 100644 maven-archetype-simple/src/site/site.xml create mode 100644 maven-archetype-simple/src/test/resources/projects/it-basic/archetype.properties create mode 100644 maven-archetype-simple/src/test/resources/projects/it-basic/goal.txt create mode 160000 maven-archetype-withparent create mode 100644 plugin-versions.properties create mode 100644 pom.xml create mode 100644 rules.xml create mode 100644 src/site/site.xml create mode 100644 src/site/xdoc/download.xml.vm diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7c4adc6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,11 @@ +name: CI Java (Host) + +on: + push: + workflow_dispatch: + +jobs: + build: + name: build-sonar-site-upload + uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop + secrets: inherit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4ece4ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +nbactions.xml +test-output + +target/ +.classpath +.project +.settings/ +Thumbs.db + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse project files +.classpath +.project + +# Proguard folder generated by Eclipse +proguard/ + +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# vscode +.vscode + +# Package Files # +*.jar +*.war +*.ear% + +dependency-reduced-pom.xml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3e9a77c --- /dev/null +++ b/README.md @@ -0,0 +1,368 @@ +# Standard Maven environment + +This project maintains SOME Maven archetypes. + +## fr.ebruno.maven.archetypes:simple + +An archetype to generate a simple standalone maven project. + +### Usage + +To generate from the archetype : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-simple +``` + +parameters can be passed directly : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-simple \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +The result can be compiled with maven + +```console +cd MyApp +mvn verify +``` + +and executed with maven : + +```console +mvn exec:java -Dexec.mainClass="demo.pkg.App" +``` + +or with java (beware no dependencies in the slim jar) + +```console +cd MyAppHelloWorld +java -cp target/MyAppHelloWorld-1.0-SNAPSHOT.jar demo.pkg.App +``` + +### Web site + +a web site can be generated in `target/site/index.html` with : + +```console +mvn site +``` + +## fr.ebruno.maven.archetypes:simple-withparent + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-withparent \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +A parent pom is defined. +By default the jar is "runnable" (see `app.main.class` in `pom.xml`) + +```bash +cd Myapp +mvn verify +java -jar target/MyApp-0.1.0-SNAPSHOT.jar +``` + +## A full git+maven+docker example + +> **WARNING**: STILL WORK IN PROGESS + +This project generates a complete Java+Maven project ready for Continuous Integration (CI). +It is ready for GitFlow, SonarQube (tests, code coverage, ...). +It can produce signed artifacts, fat jars, slim runtime with jLink, native executables with GraalVM +and container images. The build itself can also be done in a container. + +### Configuration (Once) + +The configuration is done with environment variables. +For GitHub : GITHUBORG (GitHub account or organisation), GITHUB_ACTOR, GITHUB_TOKEN +and optionally for SonarQube SONAR_URL and SONAR_TOKEN (To install SonarQube see https://github.com/ebpro/sonarqube) + +For GitHub the CLI is needed (https://cli.github.com/). + +Those variables have to be stored on the CI server (see [GitHub Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)). +The script below transforms the local variables in GitHub secrets. + +```bash +bash -c 'for secret in GITHUB_ACTOR GITHUB_TOKEN SONAR_URL SONAR_TOKEN; do \ +eval gh secret set $secret --app actions \ + --body ${!secret} \ + --org ${GITHUBORG} \ + --visibility all; \ +done' +``` + +## Each new project + +> **NOTE**: Short version, a wrapper script is provided (READ IT BEFORE USE). + +```bash +source <(curl -s https://raw.githubusercontent.com/ebpro/demomavenarchetype/develop/src/main/resources/archetype-resources/ci-wrappers.sh) +new-java-project +``` + +### Creation + +Generate each new project with this maven archetype (adapt at least the bold parameters). + +```bash +mvn --batch-mode archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-withparent \ + -DgithubAccount=$GITHUB_ORG \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +To enable deployment in the repo during the CI a deployment key is needed for each repository. + +```bash +tmpKeydir=$(mktemp --directory /tmp/ci-wrappers.XXXXXX) +ssh-keygen -q -t ed25519 -C "An autogenerated deploy key" -N "" -f ${tmpKeydir}/key +gh repo deploy-key add --allow-write "${tmpKeydir}/key.pub" +gh secret set SECRET_DEPLOY_KEY < "${tmpKeydir}/key" +rm -rf tmpKeydir +``` + +### GitFlow + +1. Initialize git environment for GitFlow (develop and master branches). +2. Make a first commit. +3. Create the GitHub repository with the [GitHub Command line Interface](https://cli.github.com/). +4. Create an orphan gh-pages branch for the website. +5. Open the repository in a web browser. + +```bash +git flow init -d && touch README.md && git add . && git commit -m "sets initial release." &&\ + gh repo create ${GITHUBORG}/${PWD##*/} --disable-wiki --private --source=. --push &&\ + git checkout --orphan gh-pages && \ + git rm -rf . && touch index.html && \ + git add . && \ + git commit -m "sets initial empty site." && \ + git push --all \ + && git checkout develop &&\ + gh repo view --web +``` + +The project uses the [gitflow-maven-plugin](https://aleksandr-m.github.io/gitflow-maven-plugin) to manage GitFlow for java+Maven projet (branches and artifact version). + +It is possible to easily start and finish a feature (see version in pom.xml). + +```bash +mvn -B gitflow:feature-start -DpushRemote=true -DfeatureName=UI +mvn -B gitflow:feature-start -DpushRemote=true -DfeatureName=DB + +mvn -B gitflow:feature-finish -DpushRemote=true -DfeatureName=DB +mvn -B gitflow:feature-finish -DpushRemote=true -DfeatureName=UI +``` + +```bash +mvn -B gitflow:release-start -DpushRemote=true -DallowSnapshots=true -DuseSnapshotInRelease=true +mvn -B gitflow:release-finish -DpushRemote=true -DallowSnapshots=true +``` + +## Artefact packaging + +### Compilation and execution + +You can compile and package with unit tests. + +```bash +mvn package +``` + +You can compile and package with unit tests and integration tests. + +```bash +mvn verify +``` + +You can execute with maven (see app.mainClass property in pom.xml). + +```bash +mvn exec:java +``` + +### Shaded Jar (close to FatJar or UberJar) + +The profile `shadedjar` generates a fat jar with all the classes from the transitive dependencies. + +```bash +mvn -Pshadedjar clean verify +ls -lh target/*.jar +``` + +```console +-rw-r--r--@ 1 bruno wheel 3.1K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-sources.jar +-rw-r--r--@ 1 bruno wheel 2.6K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-test-sources.jar +-rw-r--r--@ 1 bruno wheel 38K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-withdependencies.jar +-rw-r--r--@ 1 bruno wheel 4.2K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT.jar +``` + +The application can then be executed without maven : + +```bash +java -jar target/*-withdependencies.jar +``` + +### Jlink + +Thanks to Jlink and a modular java project (jigsaw), it is possible to generate a minimal JRE with needed modules and dependencies. + +```bash +mvn -Pjlink clean verify +du -hs target/image +``` + +```console + 44M target/image + ``` + +The application can then be launched without a JRE installed. + +```bash +./target/image/bin/myapp +``` + +```console +Dec 02, 2022 11:18:56 PM fr.univtln.bruno.demos.App main +INFOS: Hello World! [] +``` + +### GraalVM + +It is also possible to generate a native binary with [GraalVM](https://www.graalvm.org/). An installation of GraalVM is needed and the package build-essential libz-dev and zlib1g-dev (zlib-devel, zlib-static et glibc-static). Only tested in linux. + +```bash +sdk install java 22.3.r19-grl +sdk use java 22.3.r19-grl +``` + +```bash +mvn -Pnative clean verify +ls -lh target/testci +``` + +```console +-rwxr-xr-x 1 bruno users 13M 3 déc. 00:12 target/testci +``` + +```console +./target/testci +déc. 03, 2022 12:15:25 AM fr.univtln.bruno.demos.App main +INFO: Hello World! [] +``` + +### Building with Maven in docker + +It is possible to build and run the project with just docker installed. A wrapper to run maven and java +in a container but to work with the current directory is proposed. ~/.m2, ~/.ssh, ~/.gitconfig and the src directories are mounted. +The environment variables needed for the project are also transmitted. The UID and GID are the one of the current user. + +```bash +docker-mvn clean -P shadedjar package +docker run --rm \ + --mount type=bind,source="$(PWD)"/target/,target=/app,readonly \ + eclipse-temurin:17-jre-alpine \ + sh -c "java -jar /app/*-withdependencies.jar" +``` + +### Docker Multistage build + +The file `docker\Dockerfile` is a multistage Dockerfile to build and deliver +the application with several strategies (shaded jar, jlink, GraalVM) +on several distributions (debian and alpine). +To ease the use a wrapper for docker commands is provided in dockerw.sh + +```bash +. ./ci-wrappers.sh +docker-wrapper-build +docker-wrapper-run +``` + +It is also possible to build all final target (Warning graalvm takes a long time to compile). + +```bash +docker-wrapper-build-all +``` + +the result show the images and their size. + +```bash +ebpro/testci develop-finalShadedjarDebian af3e072b35f7 2 hours ago 266MB +ebpro/testci develop-finalShadedjarAlpine 38973a2aa588 2 hours ago 170MB +ebpro/testci develop-finaljLinkDebian db847ca5b281 2 hours ago 133MB +ebpro/testci develop-finalJLinkAlpine 0cba42a81a33 2 hours ago 58.2MB +ebpro/testci develop-finalGraalvmDebian f5607a1e055f 2 hours ago 93.7MB +ebpro/testci develop-finalGraalvmAlpine d9c0573e4750 2 hours ago 18.8MB +``` + +It is also possible to run all the images : + +```bash +docker-wrapper-run-all +``` + +```log +INFO: Hello World! [] + 0,06s user 0,04s system 6% cpu 1,529 total +Running ebpro/testci:develop-finalShadedjarAlpine +Dec 05, 2022 4:37:06 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,05s system 5% cpu 1,724 total +Running ebpro/testci:develop-finaljLinkDebian +Dec 05, 2022 4:37:07 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,05s system 5% cpu 1,690 total +Running ebpro/testci:develop-finalJLinkAlpine +Dec 05, 2022 4:37:09 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,04s user 0,05s system 5% cpu 1,723 total +Running ebpro/testci:develop-finalGraalvmDebian +Dec 05, 2022 4:37:10 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,03s system 7% cpu 1,161 total +Running ebpro/testci:develop-finalGraalvmAlpine +Dec 05, 2022 4:37:12 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] +``` + +### Quality + +If a sonarqube server is available (i.e with https://github.com/ebpro/sonarqube). +Set the variable SONAR_URL and SONAR_TOKEN + +```bash +mvn -P jacoco,sonar \ + -Dsonar.branch.name=$(git rev-parse --abbrev-ref HEAD | tr / _) \ + verify sonar:sonar +``` + +### TODO: FIX LOST CODE COVERAGE + +```bash +mvn clean verify +mvn -DskipTests=true \ + -Dsonar.branch.name=$(git rev-parse --abbrev-ref HEAD | tr / _) \ + -P jacoco,sonar \ + sonar:sonar +``` + +### Web site + +```bash +mvn site:site +``` diff --git a/dependency-version.properties b/dependency-version.properties new file mode 100644 index 0000000..b78b405 --- /dev/null +++ b/dependency-version.properties @@ -0,0 +1 @@ +dep_jupyter 5.9.3 \ No newline at end of file diff --git a/maven-archetype-simple/pom.xml b/maven-archetype-simple/pom.xml new file mode 100644 index 0000000..f5df196 --- /dev/null +++ b/maven-archetype-simple/pom.xml @@ -0,0 +1,25 @@ + + + + 4.0.0 + + + fr.ebruno.maven.archetypes + maven-archetype-bundles + 0.1.0-SNAPSHOT + + + maven-archetype-simple + maven-archetype + + + UTF-8 + + + Maven Simple Project Archetype + + An archetype which contains a simple Maven project. + + + diff --git a/maven-archetype-simple/src/main/resources-filtered/archetype-resources/pom.xml b/maven-archetype-simple/src/main/resources-filtered/archetype-resources/pom.xml new file mode 100644 index 0000000..c231045 --- /dev/null +++ b/maven-archetype-simple/src/main/resources-filtered/archetype-resources/pom.xml @@ -0,0 +1,83 @@ + + + + 4.0.0 + + \${groupId} + \${artifactId} + \${version} + + \${artifactId} + A simple \${artifactId}. + + https://www.example.com + + + UTF-8 + 8 + 8 + + + + + org.junit.jupiter + junit-jupiter-engine + ${dep_jupyter} + test + + + + + + + + maven-clean-plugin + ${clean} + + + maven-site-plugin + ${site} + + + maven-project-info-reports-plugin + ${pir} + + + + maven-resources-plugin + ${resources} + + + maven-compiler-plugin + ${compiler} + + + maven-surefire-plugin + ${surefire} + + + maven-jar-plugin + ${jar} + + + maven-install-plugin + ${install} + + + maven-deploy-plugin + ${deploy} + + + + + + + + + maven-project-info-reports-plugin + + + + diff --git a/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..bd22a3a --- /dev/null +++ b/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,20 @@ + + + + + + src/main/java + + + src/test/java + + + src/site + + + .mvn + + + diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/jvm.config b/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/jvm.config new file mode 100644 index 0000000..e69de29 diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/maven.config b/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/maven.config new file mode 100644 index 0000000..e69de29 diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-simple/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..9d9e32b --- /dev/null +++ b/maven-archetype-simple/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,13 @@ +package ${package}; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/src/site/site.xml b/maven-archetype-simple/src/main/resources/archetype-resources/src/site/site.xml new file mode 100644 index 0000000..8305641 --- /dev/null +++ b/maven-archetype-simple/src/main/resources/archetype-resources/src/site/site.xml @@ -0,0 +1,26 @@ + + + + + ${artifactId} + https://maven.apache.org/images/apache-maven-project.png + https://www.apache.org/ + + + + https://maven.apache.org/images/maven-logo-black-on-white.png + https://maven.apache.org/ + + + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + + + + + + \ No newline at end of file diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java b/maven-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 0000000..31742c9 --- /dev/null +++ b/maven-archetype-simple/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,21 @@ +package ${package}; + +import org.junit.jupiter.api.DisplayName; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +/** + * Unit test for simple App. + */ +public class AppTest +{ + /** + * Rigourous Test :-) + */ + @DisplayName("Dummy test successful") + @Test + public void testApp() + { + assertTrue( true ); + } +} diff --git a/maven-archetype-simple/src/site/markdown/README.md.vm b/maven-archetype-simple/src/site/markdown/README.md.vm new file mode 100644 index 0000000..35230ab --- /dev/null +++ b/maven-archetype-simple/src/site/markdown/README.md.vm @@ -0,0 +1,54 @@ +# ${project.name} + + <<<${project.artifactId}>>> is an archetype which generates a simple Maven project: + +## Usage + +To generate from the archetype : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=${project.groupId} \ + -DarchetypeArtifactId=${project.artifactId} \ + -DarchetypeVersion=${project.version} +``` + +parameters can be passed directly : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-simple \ + -DarchetypeVersion=0.1-SNAPSHOT \ + -DgroupId=demo.pkg \ + -DartifactId=MyAppHelloWorld \ + -Dversion=1.0-SNAPSHOT +``` + +The result can be compiled with maven + +```console +cd MyAppHelloWorld +mvn verify +``` + +and executed with maven : + +```console +mvn exec:java -Dexec.mainClass="demo.pkg.App" +``` + +or with java (beware no dependencies in the slim jar) + +```console +cd MyAppHelloWorld +java -cp target/MyAppHelloWorld-1.0-SNAPSHOT.jar demo.pkg.App +``` + +## Web site + +a web site can be generated in `target/site/index.html` with : + +```console +mvn site +``` diff --git a/maven-archetype-simple/src/site/site.xml b/maven-archetype-simple/src/site/site.xml new file mode 100644 index 0000000..493406e --- /dev/null +++ b/maven-archetype-simple/src/site/site.xml @@ -0,0 +1,8 @@ + + + + + + + \ No newline at end of file diff --git a/maven-archetype-simple/src/test/resources/projects/it-basic/archetype.properties b/maven-archetype-simple/src/test/resources/projects/it-basic/archetype.properties new file mode 100644 index 0000000..560ad94 --- /dev/null +++ b/maven-archetype-simple/src/test/resources/projects/it-basic/archetype.properties @@ -0,0 +1,4 @@ +package=it.pkg +version=0.1.0-SNAPSHOT +groupId=archetype.it +artifactId=basic-simple diff --git a/maven-archetype-simple/src/test/resources/projects/it-basic/goal.txt b/maven-archetype-simple/src/test/resources/projects/it-basic/goal.txt new file mode 100644 index 0000000..5c39958 --- /dev/null +++ b/maven-archetype-simple/src/test/resources/projects/it-basic/goal.txt @@ -0,0 +1 @@ +verify site \ No newline at end of file diff --git a/maven-archetype-withparent b/maven-archetype-withparent new file mode 160000 index 0000000..597e03e --- /dev/null +++ b/maven-archetype-withparent @@ -0,0 +1 @@ +Subproject commit 597e03e024bc99e955ab1068f950d6481727b8e3 diff --git a/plugin-versions.properties b/plugin-versions.properties new file mode 100644 index 0000000..5287882 --- /dev/null +++ b/plugin-versions.properties @@ -0,0 +1,17 @@ +clean 3.1.0 +site 3.12.1 +install 2.5.2 +deploy 2.8.2 +resources 3.2.0 +compiler 3.8.1 +surefire 2.22.2 +jar 3.2.0 +ejb 3.1.0 +plugin 3.6.0 +war 3.3.1 +ear 3.2.0 +rar 2.4 +archetype 3.2.0 +invoker 3.2.1 +pir 3.1.1 +javadoc 3.2.0 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fcdc1b1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + fr.ebruno.maven.archetypes + maven-archetype-bundles + 0.1.0-SNAPSHOT + pom + + Apache Maven archetypes + Standard Maven archetypes + https://github.com/ebpro/maven-archetypes + + + maven-archetype-simple + maven-archetype-withparent + + + + + ebpro + + UTF-8 + archetypes-archives/archetypes-LATEST + + + + + apache.snapshots + Apache Snapshot Repository + https://repository.apache.org/snapshots + + false + + + + + + + + org.apache.maven.archetype + archetype-packaging + 3.2.0 + + + + + src/main/resources + + + src/main/resources-filtered + true + + + + ../plugin-versions.properties + ../dependency-version.properties + + + + + org.apache.maven.plugins + maven-archetype-plugin + 3.2.0 + + true + + ${https.protocols} + + + + + org.codehaus.groovy + groovy-xml + 2.4.16 + + + + + org.apache.maven.plugins + maven-resources-plugin + + \ + + + + + + diff --git a/rules.xml b/rules.xml new file mode 100644 index 0000000..92b03f7 --- /dev/null +++ b/rules.xml @@ -0,0 +1,16 @@ + + + + + (?i).*Alpha(?:-?\d+)? + (?i).*a(?:-?\d+)? + (?i).*Beta(?:-?\d+)? + (?i).*-B(?:-?\d+)? + (?i).*RC(?:-?\d+)? + (?i).*CR(?:-?\d+)? + (?i).*M(?:-?\d+)? + .*jre[0-9]+$ + + + + \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml new file mode 100644 index 0000000..8cf6437 --- /dev/null +++ b/src/site/site.xml @@ -0,0 +1,41 @@ + + + + + + + ${project.scm.url} + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm new file mode 100644 index 0000000..9f1ef1a --- /dev/null +++ b/src/site/xdoc/download.xml.vm @@ -0,0 +1,126 @@ + + + + + + + Download ${project.name} Source + + +
+ +

${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build + ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.

+ +

You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 + hours to reach all mirrors.

+ +

In order to guard against corrupted downloads/installations, it is highly recommended to + verify the signature + of the release bundles against the public KEYS used by the Apache Maven + developers.

+ +

${project.name} is distributed under the Apache License, version 2.0.

+ +

We strongly encourage our users to configure a Maven repository mirror closer to their location, please read How to Use Mirrors for Repositories.

+ + + + +

+ [if-any logo] + + logo + + [end] + The currently selected mirror is + [preferred]. + If you encounter a problem with this mirror, + please select another mirror. + If all mirrors are failing, there are + backup + mirrors + (at the end of the mirrors list) that should be available. +

+ +
+ Other mirrors: + + +
+ +

+ You may also consult the + complete list of + mirrors. +

+ + + + + +

This is the current stable version of ${project.name}.

+ + + + + + + + + + + + + + + + + + +
LinkChecksumSignature
${project.name} ${project.version} (Source zip)maven/archetype/${project.artifactId}-${project.version}-source-release.zipmaven/archetype/${project.artifactId}-${project.version}-source-release.zip.sha512maven/archetype/${project.artifactId}-${project.version}-source-release.zip.asc
+
+ + + +

Older non-recommended releases can be found on our archive site.

+ +
+
+ +
+ From e4d79132d13f06840bc0e5ed3047c265057351ca Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sat, 20 May 2023 17:34:39 +0200 Subject: [PATCH 02/22] first version of the two main archetypes --- maven-archetype-withparent | 1 - maven-archetype-withparent/pom.xml | 22 +++ .../META-INF/maven/archetype-metadata.xml | 90 ++++++++++++ .../archetype-resources/.dockerignore | 2 + .../.github/workflows-advanced/ci.yml | 11 ++ .../.github/workflows/basic-java.yml | 77 ++++++++++ .../resources/archetype-resources/.gitignore | 42 ++++++ .../archetype-resources/docker/Dockerfile | 137 ++++++++++++++++++ .../docker/ci-settings.xml | 67 +++++++++ .../docker/docker-compose.yml | 14 ++ .../resources/archetype-resources/pom.xml | 86 +++++++++++ .../resources/archetype-resources/rules.xml | 19 +++ .../src/main/java/App.java | 40 +++++ .../src/main/java/module-info.java | 9 ++ .../src/main/java/package-info.java | 4 + .../src/main/resources/demoI18N_en.properties | 2 + .../src/main/resources/demoI18N_fr.properties | 2 + .../src/site/markdown/README.md.vm | 13 ++ .../archetype-resources/src/site/site.xml | 54 +++++++ .../src/test-integration/java/AppIT.java | 20 +++ .../src/test/java/AppTest.java | 30 ++++ .../src/test/java/SampleTest.java | 51 +++++++ .../src/site/markdown/README.md.vm | 52 +++++++ maven-archetype-withparent/src/site/site.xml | 51 +++++++ .../projects/it-basic/archetype.properties | 5 + .../test/resources/projects/it-basic/goal.txt | 1 + 26 files changed, 901 insertions(+), 1 deletion(-) delete mode 160000 maven-archetype-withparent create mode 100644 maven-archetype-withparent/pom.xml create mode 100644 maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.dockerignore create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/docker/docker-compose.yml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/rules.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_en.properties create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java create mode 100644 maven-archetype-withparent/src/site/markdown/README.md.vm create mode 100644 maven-archetype-withparent/src/site/site.xml create mode 100644 maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties create mode 100644 maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt diff --git a/maven-archetype-withparent b/maven-archetype-withparent deleted file mode 160000 index 597e03e..0000000 --- a/maven-archetype-withparent +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 597e03e024bc99e955ab1068f950d6481727b8e3 diff --git a/maven-archetype-withparent/pom.xml b/maven-archetype-withparent/pom.xml new file mode 100644 index 0000000..c88f50f --- /dev/null +++ b/maven-archetype-withparent/pom.xml @@ -0,0 +1,22 @@ + + + + 4.0.0 + + + fr.ebruno.maven.archetypes + maven-archetype-bundles + 0.1-SNAPSHOT + + + maven-archetype-withparent + maven-archetype + + Maven Full Project Archetype + A maven archetype for CI java applications + + + UTF-8 + + + diff --git a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..51e2c02 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,90 @@ + + + + + + + + + + + + src/main/java + + **/*.java + + + module-info.java + + + + src/main/java + + module-info.java + + + + src/main/resources + + **/* + + + + src/test/java + + **/*.java + + + + src/test/resources + + **/* + + + + src/test-integration/java + + **/*.java + + + + src/test-integration/resources + + **/* + + + + src/site + + **/* + + + + + + .dockerignore + .gitignore + wrappers.sh + mvnw.sh + rules.xml + README.md + + + + .github + + **/* + + + + docker + + **/* + + + + + diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.dockerignore b/maven-archetype-withparent/src/main/resources/archetype-resources/.dockerignore new file mode 100644 index 0000000..dace21d --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.dockerignore @@ -0,0 +1,2 @@ +target +.github diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml new file mode 100644 index 0000000..7c4adc6 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml @@ -0,0 +1,11 @@ +name: CI Java (Host) + +on: + push: + workflow_dispatch: + +jobs: + build: + name: build-sonar-site-upload + uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop + secrets: inherit diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml new file mode 100644 index 0000000..1a7402c --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml @@ -0,0 +1,77 @@ +name: Java CI + +on: [ push ] + +env: + GITHUBLOGIN: ${{secrets.GITHUBLOGIN}} + GITHUBTOKEN: ${{secrets.GITHUBTOKEN}} + SONAR_URL: ${{secrets.SONAR_URL}} + SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} + DOCKERHUB_USERNAME: ${{secrets.DOCKERHUB_USERNAME}} + DOCKERHUB_TOKEN: ${{secrets.DOCKERHUB_TOKEN}} + +jobs: + # This job build, test and stage the artefact and the website for the develop branch + maven-build-test-site: + # The tags to select the runner + runs-on: [ self-hosted, Linux ] + steps: + # Environment setup + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '17' + cache: 'maven' + - name: Set up Maven + uses: stCarolas/setup-maven@v4.5 + with: + maven-version: 3.8.6 + - name: Extract branch name + shell: bash + run: echo "MY_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr / _)" >> $GITHUB_ENV + # Build and test + - name: Build and Test with Maven + run: > + mvn --batch-mode \ + --update-snapshots \ + --color always \ + --settings docker/ci-settings.xml \ + -P jacoco \ + verify + # Check quality with SonarQube + ### THIS STEP MUST BE ENABLED BY CONFIGURING : SONAR_URL and SONAR_TOKEN secrets. + - name: Quality check with Sonarqube + shell: bash + if: env.SONAR_URL != null && env.SONAR_TOKEN != null + run: > + mvn -DskipTests=true \ + --batch-mode \ + --color always \ + --settings docker/ci-settings.xml \ + -Dsonar.branch.name=$MY_BRANCH \ + -P jacoco,sonar \ + sonar:sonar + # Stage artifact + - run: mkdir staging && cp target/*.jar staging + - name: Stage artifacts + uses: actions/upload-artifact@v3 + with: + name: Package + path: staging + - name: Install SSH Key + uses: webfactory/ssh-agent@v0.7.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + # Build and deploy project site + - name: Build and deploy site with Maven + if: ${{github.ref == 'refs/heads/develop'}} + run: > + mvn --batch-mode \ + --color always \ + --settings docker/ci-settings.xml \ + site:site site-deploy \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore b/maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore new file mode 100644 index 0000000..eff5a72 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore @@ -0,0 +1,42 @@ +target/ +.classpath +.project +.settings/ +Thumbs.db + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse project files +.classpath +.project + +# Proguard folder generated by Eclipse +proguard/ + +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# Package Files # +*.jar +*.war +*.ear% + +dependency-reduced-pom.xml \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile new file mode 100644 index 0000000..fc08ec0 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile @@ -0,0 +1,137 @@ +# syntax=docker/dockerfile:1 + + +########## BUILD IN UBUNTU ########## +FROM maven:3.8-eclipse-temurin-17-focal AS ubuntubuild +# We get important parameters as build-args +# and we transfer them as env variable (for maven settings substitution) with ENV. +# WARNING NEVER IN THE LAST STAGE +ARG GITHUB_LOGIN +ARG GITHUB_TOKEN +ARG SONAR_URL +ARG SONAR_TOKEN +ARG DOCKER_LOGIN +ARG DOCKER_TOKEN +ARG IMAGE_NAME +ENV GITHUB_LOGIN="$GITHUB_LOGIN" +ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV SONAR_URL="$SONAR_URL" +ENV SONAR_TOKEN="$SONAR_TOKEN" +ENV DOCKER_LOGIN="$DOCKER_LOGIN" +ENV DOCKER_TOKEN="$DOCKER_TOKEN" +ENV IMAGE_NAME="$IMAGE_NAME" +# The will be build in /myproject directory in the container +WORKDIR /myproject +# We copy the sources +COPY pom.xml . +COPY src src +# and specific settings.xml for CI +COPY docker/ci-settings.xml . +# We build the project and produce the artefact +RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \ + mvn -s ci-settings.xml -B -Pshadedjar clean verify + +########## SHADED JAR FROM UBUNTU TO UBUNTU JRE ########## +FROM eclipse-temurin:17-jre-jammy AS finalShadedjarDebian +ENV IMAGE_NAME=${IMAGE_NAME} +COPY --from=ubuntubuild /myproject/target/*-withdependencies.jar /${IMAGE_NAME}.jar +ENTRYPOINT java -jar /${IMAGE_NAME}.jar +########## SHADED JAR FROM UBUNTU TO ALPINE ########## +FROM eclipse-temurin:17-jre-alpine AS finalShadedjarAlpine +COPY --from=ubuntubuild /myproject/target/*-withdependencies.jar /${IMAGE_NAME}.jar +ENTRYPOINT java -jar /${IMAGE_NAME}.jar + +########## JLINK FROM UBUNTU to DEBIAN ########## +FROM ubuntubuild AS jlinkUbuntuBuild +RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \ + mvn -s ci-settings.xml -B -Pjlink verify +FROM debian:bullseye-slim AS finaljLinkDebian +# Copy the JRE and the modules +COPY --from=jlinkUbuntuBuild /myproject/target/image /${IMAGE_NAME} +ENTRYPOINT /${IMAGE_NAME}/bin/myapp + +########## JLINK FROM ALPINE (needed for the right JRE binary) to ALPINE ########## +FROM maven:3.8.6-eclipse-temurin-17-alpine AS jlinkAlpineBuild +ARG GITHUB_LOGIN +ARG GITHUB_TOKEN +ARG SONAR_URL +ARG SONAR_TOKEN +ARG DOCKER_LOGIN +ARG DOCKER_TOKEN +ARG IMAGE_NAME +ENV GITHUB_LOGIN="$GITHUB_LOGIN" +ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV SONAR_URL="$SONAR_URL" +ENV SONAR_TOKEN="$SONAR_TOKEN" +ENV DOCKER_LOGIN="$DOCKER_LOGIN" +ENV DOCKER_TOKEN="$DOCKER_TOKEN" +ENV IMAGE_NAME="$IMAGE_NAME" +WORKDIR /myproject +COPY pom.xml . +COPY src src +COPY docker/ci-settings.xml . +RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \ + mvn -s ci-settings.xml -B -Pjlink clean verify +FROM alpine AS finalJLinkAlpine +ARG IMAGE_NAME +ENV IMAGE_NAME=${IMAGE_NAME} +COPY --from=jlinkAlpineBuild /myproject/target/image /${IMAGE_NAME} +ENTRYPOINT /${IMAGE_NAME}/bin/myapp + +########## GRAALVM FROM DEBIAN to DEBIAN and ALPINE ########## +FROM debian:11-slim AS graalvmBuild +ARG JAVA_VERSION="22.3.r17-grl" +ARG MAVEN_VERSION="3.8.6" +ENV SDKMAN_DIR=/root/.sdkman + +ARG GITHUB_LOGIN +ARG GITHUB_TOKEN +ARG SONAR_URL +ARG SONAR_TOKEN +ARG DOCKER_LOGIN +ARG DOCKER_TOKEN +ARG IMAGE_NAME +ENV GITHUB_LOGIN="$GITHUB_LOGIN" +ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV SONAR_URL="$SONAR_URL" +ENV SONAR_TOKEN="$SONAR_TOKEN" +ENV DOCKER_LOGIN="$DOCKER_LOGIN" +ENV DOCKER_TOKEN="$DOCKER_TOKEN" +ENV IMAGE_NAME="$IMAGE_NAME" +RUN apt-get update && apt-get install -y --no-install-recommends tzdata curl zip unzip build-essential libz-dev zlib1g-dev ca-certificates fontconfig locales \ + && rm -rf /var/lib/apt/lists/* \ + && echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen \ + && locale-gen en_US.UTF-8 \ + && curl 'https://get.sdkman.io' | bash \ + && echo "sdkman_auto_answer=true" > $SDKMAN_DIR/etc/config \ + && echo "sdkman_auto_selfupdate=false" >> $SDKMAN_DIR/etc/config \ + && echo "sdkman_insecure_ssl=true" >> $SDKMAN_DIR/etc/config \ + && chmod +x $SDKMAN_DIR/bin/sdkman-init.sh +SHELL ["/bin/bash", "-c"] +RUN source $SDKMAN_DIR/bin/sdkman-init.sh \ + && sdk version \ + && sdk install java $JAVA_VERSION \ + && gu install native-image \ + && gu install js \ + && sdk install maven $MAVEN_VERSION \ + && rm -rf $SDKMAN_DIR/archives/* \ + && rm -rf $SDKMAN_DIR/tmp/* +WORKDIR /myproject +COPY pom.xml . +COPY src src +COPY docker/ci-settings.xml . +RUN --mount=type=cache,id=mvncache,target=/root/.m2/repository,rw \ + source $SDKMAN_DIR/bin/sdkman-init.sh && \ + mvn -s ci-settings.xml -B -Pnative clean verify + +FROM debian:11-slim AS finalGraalvmDebian +ARG IMAGE_NAME +ENV IMAGE_NAME=${IMAGE_NAME} +COPY --from=graalvmBuild /myproject/target/${IMAGE_NAME} / +ENTRYPOINT /${IMAGE_NAME} + +FROM alpine as finalGraalvmAlpine +ARG IMAGE_NAME +ENV IMAGE_NAME=${IMAGE_NAME} +COPY --from=graalvmBuild /myproject/target/${IMAGE_NAME} / +ENTRYPOINT /${IMAGE_NAME} diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml new file mode 100644 index 0000000..302bf8d --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml @@ -0,0 +1,67 @@ + + + + + + github + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + gpg.passphrase + ${env.GPG_PASSPHRASE} + + + github.pages + git + + branch + gh-pages + + + + dockerhub + ${env.DOCKER_USERNAME} + ${env.DOCKER_PASSWORD} + + + maven + ${env.MAVEN_USERNAME} + ${env.MAVEN_CENTRAL_TOKEN} + + + + + + sonar + + ${env.SONAR_URL} + ${env.SONAR_TOKEN} + + + + github + + + central + https://repo1.maven.org/maven2 + + + github + https://maven.pkg.github.com/ebpro/* + + true + + + + + + + + + github + + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/docker-compose.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/docker-compose.yml new file mode 100644 index 0000000..7f39fce --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/docker-compose.yml @@ -0,0 +1,14 @@ +services: + myapp: + image: ${DOCKER_REPO_NAME}/${IMAGE_NAME}:${IMAGE_TAG} + build: + context: .. + dockerfile: /Dockerfile + args: + - DOCKER_USERNAME=${DOCKER_USERNAME} + - DOCKER_TOKEN=${DOCKER_TOKEN} + - SONAR_URL=${SONAR_URL} + - SONAR_TOKEN=${SONAR_TOKEN} + - GITHUBLOGIN=${GITHUBLOGIN} + - GITHUBTOKEN=${GITHUBTOKEN} + - IMAGE_NAME=${IMAGE_NAME} \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..9d1a5e4 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + + fr.ebruno.maven.poms + maven-parentpom + 0.1.0-SNAPSHOT + + + ${groupId} + ${artifactId} + ${version} + + + ${package}.App + ${githubAccount} + + + + ${artifactId} + 2022 + + + + + + org.projectlombok + lombok + provided + + + + + org.junit.jupiter + junit-jupiter-engine + + + + + ch.qos.logback + logback-classic + + + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + + + + https://github.com/${github.account}/${project.artifactId}/tree/${project.scm.tag} + scm:git:git@github.com:${github.account}/${project.artifactId}.git + scm:git:git@github.com:${github.account}/${project.artifactId}.git + + + diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/rules.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/rules.xml new file mode 100644 index 0000000..f07d9ee --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/rules.xml @@ -0,0 +1,19 @@ + + + + + (?i).*Alpha(?:-?\d+)? + (?i).*a(?:-?\d+)? + (?i).*Beta(?:-?\d+)? + (?i).*-B(?:-?\d+)? + (?i).*RC(?:-?\d+)? + (?i).*CR(?:-?\d+)? + (?i).*M(?:-?\d+)? + .*jre[0-9]+$ + + + + diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..b1db7c2 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,40 @@ +package $package; + +import lombok.extern.java.Log; + +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * A simple starting App ready for CI. + */ +@Log +public class App { + /** + * A resource bundle for I18N internationalisation. + */ + private static ResourceBundle i18Nbundle = ResourceBundle.getBundle("demoI18N", Locale.getDefault()); + + /** + * A simple main() with log and local. + * + * @param args the CLI parameters + */ + public static void main(String[] args) { + log.info(MessageFormat.format(i18Nbundle.getString("helloworld"), Arrays.toString(args))); + } + + /** + * A sample method to illustrate tests. + * @param x a positive int + * @param y a positive int + * @return the int value of the sum of x and y + */ + public int add(int x, int y) { + if (x < 0 || y < 0) throw new NumberFormatException(i18Nbundle.getString("parameter.format.positive")); + return x + y; + } +} + diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java new file mode 100644 index 0000000..198895d --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java @@ -0,0 +1,9 @@ +/** + * A simple jigsaw module + */ +module $package.$artifactId { + requires java.logging; + requires static lombok; + + exports $package; +} diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java new file mode 100644 index 0000000..08483c9 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java @@ -0,0 +1,4 @@ +/** + * A simple package documentation + */ +package $package; \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_en.properties b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_en.properties new file mode 100644 index 0000000..5b9b881 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_en.properties @@ -0,0 +1,2 @@ +helloworld=Hello world ! +parameter.format.positive=Parameter has to be positive. diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties new file mode 100644 index 0000000..f13b573 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties @@ -0,0 +1,2 @@ +helloworld=Bonjour à tous ! +parameter.format.positive=Parameter has to be positive. diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm new file mode 100644 index 0000000..20360dc --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm @@ -0,0 +1,13 @@ +# Usage +This simple Java Project is ready for Continuous Integration (CI). + +The application can simply be packaged without and with dependencies. +The default main class of the manifest is defined (see pom.xml). +```console +# Compile, run unit and integration tests (the shade plugin generate two artifacts) and package. +mvn verify +# Execution from Maven +mvn exec:java +# Execution as a uber jar +java -jar target/myapp-${project.version}-withdependencies.jar +``` \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml new file mode 100644 index 0000000..ca5eb57 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml @@ -0,0 +1,54 @@ + + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + + + + + + + + + + + + + + + + + + + + + + + true + false + true + + ${project.url} + + pull-right + + ${github.account}/${project.artifactId}/ + right + gray + + » + + + diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java new file mode 100644 index 0000000..6cac6d2 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java @@ -0,0 +1,20 @@ +package $package; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; + +/** + * Unit test for simple App. + */ +class AppIT +{ + /** + * Rigorous Test :-) + */ + @Test + void shouldAnswerWithTrue() + { + assertTrue( true ); + } +} diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 0000000..5f5716c --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,30 @@ +package $package; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** + * Unit test for simple App. + */ +@Slf4j +class AppTest { + + @Test + void addCorrect() { + assertEquals(5, new App().add(3, 2)); + } + + @Test + void addCheckException1() { + assertThrows(NumberFormatException.class, () -> new App().add(-3, 2)); + } + + @Test + void addCheckException2() { + assertThrows(NumberFormatException.class, () -> new App().add(3, -2)); + } + +} diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java new file mode 100644 index 0000000..57efb1b --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java @@ -0,0 +1,51 @@ +package $package; + +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.*; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.*; + +/** + * Unit test for simple App. + */ +@Slf4j +class SampleTest { + @BeforeAll + static void init() { + log.info("Once before all tests."); + } + + @AfterAll + static void close() { + log.info("Once after all tests."); + } + + @BeforeEach + void prepare() { + log.info("Before each test."); + } + + @AfterEach + void end() { + log.info("After each test."); + } + + @Test + //@Disable + void shouldAnswerWithTrue() { + //Assumption to check that tests condition are ok (optional). + //Notice the static import. + assumeTrue(10 < 100); + + assertTrue(true); + } + + @Test + void checkException() { + assertThrows(ArithmeticException.class, () -> { + int x = 3 / 0; + }); + } + +} diff --git a/maven-archetype-withparent/src/site/markdown/README.md.vm b/maven-archetype-withparent/src/site/markdown/README.md.vm new file mode 100644 index 0000000..2ce6673 --- /dev/null +++ b/maven-archetype-withparent/src/site/markdown/README.md.vm @@ -0,0 +1,52 @@ +# Usage +This archetype can create a simple Java Project ready for Continuous Integration (CI). +Set your `-DgithubAccount=` and change `-DgroupId` and `-DartifactId` to match the new application ones. + +```console +mvn archetype:generate \ + -DarchetypeGroupId=${project.groupId} \ + -DarchetypeArtifactId=${project.artifactId} \ + -DarchetypeVersion=${project.version} \ + -DgithubAccount= \ + -DgroupId=fr.univtln.bruno.demos \ + -DartifactId=myapp \ + -Dversion=1.0-SNAPSHOT +``` + +The application can simply be packaged without and with dependencies. +The default main class of the manifest is defined (see pom.xml). + +```console +cd MyApp +# Compile, runs unit and integration tests (the shade plugin generate two artifacts) and package. +mvn verify +# Execution from Maven +mvn exec:java +# Execution as a uber jar +java -jar target/myapp-${project.version}-withdependencies.jar +``` + +Artifacts can automatically be deployed to GitHub packages. + +```console +mvn deploy +``` + +A website can be automatically generated + +```console +mvn site +``` + +The website can be displayed in a local web server + +```console +mvn site:run +``` + +The website can be deployed to GitHub pages. + +```console +mvn compile +mvn site-deploy +``` \ No newline at end of file diff --git a/maven-archetype-withparent/src/site/site.xml b/maven-archetype-withparent/src/site/site.xml new file mode 100644 index 0000000..2905986 --- /dev/null +++ b/maven-archetype-withparent/src/site/site.xml @@ -0,0 +1,51 @@ + + + org.apache.maven.skins + maven-fluido-skin + 1.9 + + + + + + + + + + + + + + + + + + + + false + true + true + + ${project.url} + + + ${github.account}/${project.artifactId}/ + right + gray + + + + diff --git a/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties b/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties new file mode 100644 index 0000000..096bfd1 --- /dev/null +++ b/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties @@ -0,0 +1,5 @@ +groupId=it.pkg +artifactId=basicwithparent +version=0.1.0-SNAPSHOT +package=it.pkg +githubAccount=emmanuelbruno diff --git a/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt b/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt new file mode 100644 index 0000000..15d4fad --- /dev/null +++ b/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt @@ -0,0 +1 @@ +verify exec:java \ No newline at end of file From 36c5cd5d6bdb359b14d13fcde743b597b2febd46 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sat, 20 May 2023 17:42:02 +0200 Subject: [PATCH 03/22] adds missing ci-settings.xml --- ci-settings.xml | 67 +++++++++++++++++++ .../archetype-resources/ci-settings.xml | 67 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 ci-settings.xml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml diff --git a/ci-settings.xml b/ci-settings.xml new file mode 100644 index 0000000..302bf8d --- /dev/null +++ b/ci-settings.xml @@ -0,0 +1,67 @@ + + + + + + github + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + gpg.passphrase + ${env.GPG_PASSPHRASE} + + + github.pages + git + + branch + gh-pages + + + + dockerhub + ${env.DOCKER_USERNAME} + ${env.DOCKER_PASSWORD} + + + maven + ${env.MAVEN_USERNAME} + ${env.MAVEN_CENTRAL_TOKEN} + + + + + + sonar + + ${env.SONAR_URL} + ${env.SONAR_TOKEN} + + + + github + + + central + https://repo1.maven.org/maven2 + + + github + https://maven.pkg.github.com/ebpro/* + + true + + + + + + + + + github + + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml new file mode 100644 index 0000000..302bf8d --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml @@ -0,0 +1,67 @@ + + + + + + github + ${env.GITHUB_ACTOR} + ${env.GITHUB_TOKEN} + + + gpg.passphrase + ${env.GPG_PASSPHRASE} + + + github.pages + git + + branch + gh-pages + + + + dockerhub + ${env.DOCKER_USERNAME} + ${env.DOCKER_PASSWORD} + + + maven + ${env.MAVEN_USERNAME} + ${env.MAVEN_CENTRAL_TOKEN} + + + + + + sonar + + ${env.SONAR_URL} + ${env.SONAR_TOKEN} + + + + github + + + central + https://repo1.maven.org/maven2 + + + github + https://maven.pkg.github.com/ebpro/* + + true + + + + + + + + + github + + + \ No newline at end of file From 6367d28a6772f1560f2ae9ff7e666c3bbdf98620 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sat, 20 May 2023 18:02:11 +0200 Subject: [PATCH 04/22] adds lombok config. --- .../src/main/resources/archetype-resources/lombok.config | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/lombok.config diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/lombok.config b/maven-archetype-withparent/src/main/resources/archetype-resources/lombok.config new file mode 100644 index 0000000..b6a6266 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/lombok.config @@ -0,0 +1,9 @@ +# stop lombok from looking at parent directories for more configuration files +config.stopBubbling = true + +# No need for test coverage on Lombok generated code with JaCoCo +lombok.addLombokGeneratedAnnotation = true + +# lombok.accessors.chain = true +# lombok.anyConstructor.addConstructorProperties = true +# lombok.fieldDefaults.defaultPrivate = true \ No newline at end of file From 81c4b7496d2f6c8184a230a5bc13cb3869e15c68 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sat, 20 May 2023 18:39:26 +0200 Subject: [PATCH 05/22] fixes typo --- ci-settings.xml | 2 +- maven-archetype-simple/src/site/markdown/README.md.vm | 1 - maven-archetype-withparent/pom.xml | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ci-settings.xml b/ci-settings.xml index 302bf8d..c023009 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -50,7 +50,7 @@ github - https://maven.pkg.github.com/ebpro/* + https://maven.pkg.github.com/${env.GITHUB_ORG} true diff --git a/maven-archetype-simple/src/site/markdown/README.md.vm b/maven-archetype-simple/src/site/markdown/README.md.vm index 35230ab..b0aeaa7 100644 --- a/maven-archetype-simple/src/site/markdown/README.md.vm +++ b/maven-archetype-simple/src/site/markdown/README.md.vm @@ -19,7 +19,6 @@ parameters can be passed directly : mvn archetype:generate \ -DarchetypeGroupId=fr.ebruno.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-simple \ - -DarchetypeVersion=0.1-SNAPSHOT \ -DgroupId=demo.pkg \ -DartifactId=MyAppHelloWorld \ -Dversion=1.0-SNAPSHOT diff --git a/maven-archetype-withparent/pom.xml b/maven-archetype-withparent/pom.xml index c88f50f..45f7eb4 100644 --- a/maven-archetype-withparent/pom.xml +++ b/maven-archetype-withparent/pom.xml @@ -6,7 +6,7 @@ fr.ebruno.maven.archetypes maven-archetype-bundles - 0.1-SNAPSHOT + 0.1.0-SNAPSHOT maven-archetype-withparent From edab6f1fa6dddbc742c1e7a0f347d9f6dc6ae717 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sun, 21 May 2023 16:59:45 +0200 Subject: [PATCH 06/22] fixes parents --- README.md | 7 +- ci-settings.xml | 10 +- .../archetype-resources/ci-settings.xml | 6 +- .../resources/archetype-resources/pom.xml | 105 +++++++++--------- .../test/resources/projects/it-basic/goal.txt | 2 +- pom.xml | 11 +- 6 files changed, 74 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index 3e9a77c..7273ff7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ -# Standard Maven environment +# Best practices Maven archetypes -This project maintains SOME Maven archetypes. +This project maintains some Maven archetypes. + +* `fr.ebruno.maven.archetypes:simple` a simple standalone Java project. +* `fr.ebruno.maven.archetypes:simple-withparent`a CI ready one with a complete parent POM. ## fr.ebruno.maven.archetypes:simple diff --git a/ci-settings.xml b/ci-settings.xml index c023009..3b00444 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -9,10 +9,6 @@ ${env.GITHUB_ACTOR} ${env.GITHUB_TOKEN} - - gpg.passphrase - ${env.GPG_PASSPHRASE} - github.pages git @@ -23,8 +19,8 @@ dockerhub - ${env.DOCKER_USERNAME} - ${env.DOCKER_PASSWORD} + ${env.DOCKERHUB_USERNAME} + ${env.DOCKERHUB_TOKEN} maven @@ -50,7 +46,7 @@ github - https://maven.pkg.github.com/${env.GITHUB_ORG} + https://maven.pkg.github.com/${env.GITHUB_ORG}/* true diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml index 302bf8d..b34892b 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml @@ -23,8 +23,8 @@ dockerhub - ${env.DOCKER_USERNAME} - ${env.DOCKER_PASSWORD} + ${env.DOCKERHUB_USERNAME} + ${env.DOCKERHUB_TOKEN} maven @@ -50,7 +50,7 @@ github - https://maven.pkg.github.com/ebpro/* + https://maven.pkg.github.com/${env.GITHUB_ORG}/* true diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml index 9d1a5e4..7693789 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml @@ -1,27 +1,28 @@ - - 4.0.0 + + 4.0.0 - - fr.ebruno.maven.poms - maven-parentpom - 0.1.0-SNAPSHOT - + + fr.ebruno.maven.poms + maven-parentpom + 0.1.0-SNAPSHOT + - ${groupId} - ${artifactId} - ${version} + ${groupId} + ${artifactId} + ${version} - - ${package}.App - ${githubAccount} - - + + ${package}.App + ${githubAccount} + + - ${artifactId} - 2022 - - - - - org.projectlombok - lombok - provided - + + + + org.projectlombok + lombok + provided + - - - org.junit.jupiter - junit-jupiter-engine - + + + org.junit.jupiter + junit-jupiter-engine + - - - ch.qos.logback - logback-classic - - + + + ch.qos.logback + logback-classic + + - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + - - https://github.com/${github.account}/${project.artifactId}/tree/${project.scm.tag} - scm:git:git@github.com:${github.account}/${project.artifactId}.git - scm:git:git@github.com:${github.account}/${project.artifactId}.git - + + https://github.com/${github.account}/${project.artifactId}/tree/${project.scm.tag} + scm:git:git@github.com:${github.account}/${project.artifactId}.git + scm:git:git@github.com:${github.account}/${project.artifactId}.git + - + \ No newline at end of file diff --git a/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt b/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt index 15d4fad..659ea18 100644 --- a/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt +++ b/maven-archetype-withparent/src/test/resources/projects/it-basic/goal.txt @@ -1 +1 @@ -verify exec:java \ No newline at end of file +verify site exec:java \ No newline at end of file diff --git a/pom.xml b/pom.xml index fcdc1b1..f1ed3f5 100644 --- a/pom.xml +++ b/pom.xml @@ -1,9 +1,16 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + + fr.ebruno.maven.poms + maven-parentpom + 0.1.0-SNAPSHOT + + fr.ebruno.maven.archetypes maven-archetype-bundles 0.1.0-SNAPSHOT @@ -88,4 +95,4 @@ - + \ No newline at end of file From a61d450cffdb9842b50093ab4d8f3212c07b214e Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sun, 21 May 2023 17:48:01 +0200 Subject: [PATCH 07/22] fixes env --- ci-settings.xml | 8 ++++---- .../resources/archetype-resources/ci-settings.xml | 12 ++++-------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/ci-settings.xml b/ci-settings.xml index 3b00444..e68a6e0 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -6,8 +6,8 @@ github - ${env.GITHUB_ACTOR} - ${env.GITHUB_TOKEN} + ${env.GITHUBACTOR} + ${env.GITHUBTOKEN} github.pages @@ -42,11 +42,11 @@ central - https://repo1.maven.org/maven2 + https://repo.maven.apache.org/maven2/ github - https://maven.pkg.github.com/${env.GITHUB_ORG}/* + https://maven.pkg.github.com/${env.GITHUBORG}/* true diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml index b34892b..e68a6e0 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml @@ -6,12 +6,8 @@ github - ${env.GITHUB_ACTOR} - ${env.GITHUB_TOKEN} - - - gpg.passphrase - ${env.GPG_PASSPHRASE} + ${env.GITHUBACTOR} + ${env.GITHUBTOKEN} github.pages @@ -46,11 +42,11 @@ central - https://repo1.maven.org/maven2 + https://repo.maven.apache.org/maven2/ github - https://maven.pkg.github.com/${env.GITHUB_ORG}/* + https://maven.pkg.github.com/${env.GITHUBORG}/* true From b54fab5f656b54411e3689efcce31a175189f344 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sun, 21 May 2023 18:44:53 +0200 Subject: [PATCH 08/22] adds maven wrapper --- .gitignore | 5 +- .mvn/jvm.config | 0 .mvn/maven.config | 0 .mvn/wrapper/maven-wrapper.properties | 18 ++ maven-archetype-simple/.gitignore | 51 ++++ .../.mvn/wrapper/maven-wrapper.properties | 1 + .../archetype-resources/.mvn/jvm.config | 0 .../archetype-resources/.mvn/maven.config | 0 .../.mvn/wrapper/maven-wrapper.properties | 1 + mvnw | 287 ++++++++++++++++++ mvnw.cmd | 187 ++++++++++++ 11 files changed, 549 insertions(+), 1 deletion(-) create mode 100644 .mvn/jvm.config create mode 100644 .mvn/maven.config create mode 100644 .mvn/wrapper/maven-wrapper.properties create mode 100644 maven-archetype-simple/.gitignore create mode 100644 maven-archetype-simple/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/jvm.config create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/maven.config create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties create mode 100755 mvnw create mode 100644 mvnw.cmd diff --git a/.gitignore b/.gitignore index 4ece4ed..ea3acd2 100644 --- a/.gitignore +++ b/.gitignore @@ -45,4 +45,7 @@ proguard/ *.war *.ear% -dependency-reduced-pom.xml \ No newline at end of file +dependency-reduced-pom.xml + +# Maven Wrapper +.mvn/wrapper/maven-wrapper.jar \ No newline at end of file diff --git a/.mvn/jvm.config b/.mvn/jvm.config new file mode 100644 index 0000000..e69de29 diff --git a/.mvn/maven.config b/.mvn/maven.config new file mode 100644 index 0000000..e69de29 diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..4b40fcf --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/maven-archetype-simple/.gitignore b/maven-archetype-simple/.gitignore new file mode 100644 index 0000000..ea3acd2 --- /dev/null +++ b/maven-archetype-simple/.gitignore @@ -0,0 +1,51 @@ +nbactions.xml +test-output + +target/ +.classpath +.project +.settings/ +Thumbs.db + +# built application files +*.apk +*.ap_ + +# files for the dex VM +*.dex + +# Java class files +*.class + +# generated files +bin/ +gen/ + +# Local configuration file (sdk path, etc) +local.properties + +# Eclipse project files +.classpath +.project + +# Proguard folder generated by Eclipse +proguard/ + +# Intellij project files +*.iml +*.ipr +*.iws +.idea/ + +# vscode +.vscode + +# Package Files # +*.jar +*.war +*.ear% + +dependency-reduced-pom.xml + +# Maven Wrapper +.mvn/wrapper/maven-wrapper.jar \ No newline at end of file diff --git a/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties b/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..37eef57 --- /dev/null +++ b/maven-archetype-simple/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/jvm.config b/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/jvm.config new file mode 100644 index 0000000..e69de29 diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/maven.config b/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/maven.config new file mode 100644 index 0000000..e69de29 diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties b/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..37eef57 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip \ No newline at end of file diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..b7f0646 --- /dev/null +++ b/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..cba1f04 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% From 38bf54610f098c4e9d554bc8a8af5adddfbb5ee9 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sun, 21 May 2023 19:01:17 +0200 Subject: [PATCH 09/22] fixes GITHUB_ env --- README.md | 6 ++--- .../.github/workflows/basic-java.yml | 2 +- .../archetype-resources/docker/Dockerfile | 24 +++++++++---------- .../docker/ci-settings.xml | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7273ff7..5c3df5c 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ and container images. The build itself can also be done in a container. ### Configuration (Once) The configuration is done with environment variables. -For GitHub : GITHUBORG (GitHub account or organisation), GITHUB_ACTOR, GITHUB_TOKEN +For GitHub : GITHUBORG (GitHub account or organisation), GITHUBACTOR, GITHUBTOKEN, GITHUBORG (org or account) and optionally for SonarQube SONAR_URL and SONAR_TOKEN (To install SonarQube see https://github.com/ebpro/sonarqube) For GitHub the CLI is needed (https://cli.github.com/). @@ -99,7 +99,7 @@ Those variables have to be stored on the CI server (see [GitHub Encrypted secret The script below transforms the local variables in GitHub secrets. ```bash -bash -c 'for secret in GITHUB_ACTOR GITHUB_TOKEN SONAR_URL SONAR_TOKEN; do \ +bash -c 'for secret in GITHUBACTOR GITHUBTOKEN SONAR_URL SONAR_TOKEN; do \ eval gh secret set $secret --app actions \ --body ${!secret} \ --org ${GITHUBORG} \ @@ -124,7 +124,7 @@ Generate each new project with this maven archetype (adapt at least the bold par mvn --batch-mode archetype:generate \ -DarchetypeGroupId=fr.ebruno.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-withparent \ - -DgithubAccount=$GITHUB_ORG \ + -DgithubAccount=$GITHUBORG \ -DgroupId=demo.pkg \ -DartifactId=MyApp \ -Dversion=0.1.0-SNAPSHOT diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml index 1a7402c..dfd19da 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml @@ -3,7 +3,7 @@ name: Java CI on: [ push ] env: - GITHUBLOGIN: ${{secrets.GITHUBLOGIN}} + GITHUBACTOR: ${{secrets.GITHUBACTOR}} GITHUBTOKEN: ${{secrets.GITHUBTOKEN}} SONAR_URL: ${{secrets.SONAR_URL}} SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile index fc08ec0..13bd7e2 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/Dockerfile @@ -6,15 +6,15 @@ FROM maven:3.8-eclipse-temurin-17-focal AS ubuntubuild # We get important parameters as build-args # and we transfer them as env variable (for maven settings substitution) with ENV. # WARNING NEVER IN THE LAST STAGE -ARG GITHUB_LOGIN -ARG GITHUB_TOKEN +ARG GITHUBLOGIN +ARG GITHUBTOKEN ARG SONAR_URL ARG SONAR_TOKEN ARG DOCKER_LOGIN ARG DOCKER_TOKEN ARG IMAGE_NAME -ENV GITHUB_LOGIN="$GITHUB_LOGIN" -ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV GITHUBLOGIN="$GITHUBLOGIN" +ENV GITHUBTOKEN="$GITHUBTOKEN" ENV SONAR_URL="$SONAR_URL" ENV SONAR_TOKEN="$SONAR_TOKEN" ENV DOCKER_LOGIN="$DOCKER_LOGIN" @@ -52,15 +52,15 @@ ENTRYPOINT /${IMAGE_NAME}/bin/myapp ########## JLINK FROM ALPINE (needed for the right JRE binary) to ALPINE ########## FROM maven:3.8.6-eclipse-temurin-17-alpine AS jlinkAlpineBuild -ARG GITHUB_LOGIN -ARG GITHUB_TOKEN +ARG GITHUBLOGIN +ARG GITHUBTOKEN ARG SONAR_URL ARG SONAR_TOKEN ARG DOCKER_LOGIN ARG DOCKER_TOKEN ARG IMAGE_NAME -ENV GITHUB_LOGIN="$GITHUB_LOGIN" -ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV GITHUBLOGIN="$GITHUBLOGIN" +ENV GITHUBTOKEN="$GITHUBTOKEN" ENV SONAR_URL="$SONAR_URL" ENV SONAR_TOKEN="$SONAR_TOKEN" ENV DOCKER_LOGIN="$DOCKER_LOGIN" @@ -84,15 +84,15 @@ ARG JAVA_VERSION="22.3.r17-grl" ARG MAVEN_VERSION="3.8.6" ENV SDKMAN_DIR=/root/.sdkman -ARG GITHUB_LOGIN -ARG GITHUB_TOKEN +ARG GITHUBLOGIN +ARG GITHUBTOKEN ARG SONAR_URL ARG SONAR_TOKEN ARG DOCKER_LOGIN ARG DOCKER_TOKEN ARG IMAGE_NAME -ENV GITHUB_LOGIN="$GITHUB_LOGIN" -ENV GITHUB_TOKEN="$GITHUB_TOKEN" +ENV GITHUBLOGIN="$GITHUBLOGIN" +ENV GITHUBTOKEN="$GITHUBTOKEN" ENV SONAR_URL="$SONAR_URL" ENV SONAR_TOKEN="$SONAR_TOKEN" ENV DOCKER_LOGIN="$DOCKER_LOGIN" diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml index 302bf8d..73f5268 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/docker/ci-settings.xml @@ -6,8 +6,8 @@ github - ${env.GITHUB_ACTOR} - ${env.GITHUB_TOKEN} + ${env.GITHUBACTOR} + ${env.GITHUBTOKEN} gpg.passphrase From 9ee3d53089878c8096cf478c3cbf3d5e7cf24497 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Sun, 21 May 2023 23:42:47 +0200 Subject: [PATCH 10/22] adds missing artefact files --- .../META-INF/archetype-post-generate.groovy | 3 + .../META-INF/maven/archetype-metadata.xml | 23 +- .../{.gitignore => .gitignore.template} | 0 .../main/resources/archetype-resources/mvnw | 287 ++++++++++++++++++ .../resources/archetype-resources/mvnw.cmd | 187 ++++++++++++ .../projects/it-basic/archetype.properties | 2 +- 6 files changed, 489 insertions(+), 13 deletions(-) create mode 100644 maven-archetype-withparent/src/main/resources/META-INF/archetype-post-generate.groovy rename maven-archetype-withparent/src/main/resources/archetype-resources/{.gitignore => .gitignore.template} (100%) create mode 100755 maven-archetype-withparent/src/main/resources/archetype-resources/mvnw create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd diff --git a/maven-archetype-withparent/src/main/resources/META-INF/archetype-post-generate.groovy b/maven-archetype-withparent/src/main/resources/META-INF/archetype-post-generate.groovy new file mode 100644 index 0000000..14d7b07 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/META-INF/archetype-post-generate.groovy @@ -0,0 +1,3 @@ +file = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore.template" ); +def gitIgnorefile = new File( request.getOutputDirectory(), request.getArtifactId()+"/.gitignore" ); +file.renameTo(gitIgnorefile) diff --git a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml index 51e2c02..da445a9 100644 --- a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -1,6 +1,7 @@ - @@ -66,25 +67,23 @@ .dockerignore - .gitignore + .gitignore.template wrappers.sh - mvnw.sh + mvnw + mvnw.cmd rules.xml README.md - + .github - - **/* - - + docker - - **/* - + + + .mvn - + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore b/maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore.template similarity index 100% rename from maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore rename to maven-archetype-withparent/src/main/resources/archetype-resources/.gitignore.template diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw new file mode 100755 index 0000000..b7f0646 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw @@ -0,0 +1,287 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Apache Maven Wrapper startup batch script, version 3.1.1 +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME + else + JAVA_HOME="/Library/Java/Home"; export JAVA_HOME + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + printf '%s' "$(cd "$basedir"; pwd)" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=$(find_maven_basedir "$(dirname $0)") +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + else + wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $wrapperUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + QUIET="--quiet" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" + else + wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + elif command -v curl > /dev/null; then + QUIET="--silent" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + QUIET="" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L + else + curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L + fi + [ $? -eq 0 ] || rm -f "$wrapperJarPath" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaSource=`cygpath --path --windows "$javaSource"` + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaSource" ]; then + if [ ! -e "$javaClass" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaSource") + fi + if [ -e "$javaClass" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd new file mode 100644 index 0000000..cba1f04 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd @@ -0,0 +1,187 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Apache Maven Wrapper startup batch script, version 3.1.1 +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %WRAPPER_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties b/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties index 096bfd1..1b5362e 100644 --- a/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties +++ b/maven-archetype-withparent/src/test/resources/projects/it-basic/archetype.properties @@ -2,4 +2,4 @@ groupId=it.pkg artifactId=basicwithparent version=0.1.0-SNAPSHOT package=it.pkg -githubAccount=emmanuelbruno +githubAccount=ebpro From 1ed8593e4bfd35b26e8dbcbb375de492cc2bbc18 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Tue, 23 May 2023 18:02:09 +0200 Subject: [PATCH 11/22] fixes withparent --- .mvn/wrapper/maven-wrapper.properties | 16 ------ ci-settings.xml | 51 ++++++++++++++++-- maven-archetype-simple/pom.xml | 34 ++++++++++++ maven-archetype-simple/rules.xml | 16 ++++++ .../META-INF/maven/archetype-metadata.xml | 10 ++-- maven-archetype-withparent/pom.xml | 3 ++ maven-archetype-withparent/rules.xml | 16 ++++++ .../META-INF/maven/archetype-metadata.xml | 9 ++-- .../archetype-resources/ci-settings.xml | 53 ++++++++++++++++++- .../resources/archetype-resources/pom.xml | 10 ---- .../src/main/java/App.java | 8 +++ pom.xml | 31 +++++++++-- 12 files changed, 214 insertions(+), 43 deletions(-) create mode 100644 maven-archetype-simple/rules.xml create mode 100644 maven-archetype-withparent/rules.xml diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index 4b40fcf..6e4687b 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -1,18 +1,2 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.8/apache-maven-3.8.8-bin.zip wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar diff --git a/ci-settings.xml b/ci-settings.xml index e68a6e0..8450a01 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -3,6 +3,15 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> + + github @@ -27,6 +36,11 @@ ${env.MAVEN_USERNAME} ${env.MAVEN_CENTRAL_TOKEN} + + maven-proxy + ${env.MAVENPROXY_USERNAME} + ${env.MAVENPROXY_TOKEN} + @@ -40,10 +54,6 @@ github - - central - https://repo.maven.apache.org/maven2/ - github https://maven.pkg.github.com/${env.GITHUBORG}/* @@ -54,10 +64,43 @@ + + nexus + + + central + http://central + + true + never + + + true + always + + + + + + central + http://central + + true + never + + + true + always + + + + + github + \ No newline at end of file diff --git a/maven-archetype-simple/pom.xml b/maven-archetype-simple/pom.xml index f5df196..df0086f 100644 --- a/maven-archetype-simple/pom.xml +++ b/maven-archetype-simple/pom.xml @@ -22,4 +22,38 @@ An archetype which contains a simple Maven project. + + + + maven-help-plugin + 2.2 + + ${project.build.directory}/effective-settings.xml + + + + + pre-integration-test + + effective-settings + + + + + + maven-archetype-plugin + 2.4 + + ${project.build.directory}/effective-settings.xml + + + + commons-lang + commons-lang + 2.6 + + + + + diff --git a/maven-archetype-simple/rules.xml b/maven-archetype-simple/rules.xml new file mode 100644 index 0000000..92b03f7 --- /dev/null +++ b/maven-archetype-simple/rules.xml @@ -0,0 +1,16 @@ + + + + + (?i).*Alpha(?:-?\d+)? + (?i).*a(?:-?\d+)? + (?i).*Beta(?:-?\d+)? + (?i).*-B(?:-?\d+)? + (?i).*RC(?:-?\d+)? + (?i).*CR(?:-?\d+)? + (?i).*M(?:-?\d+)? + .*jre[0-9]+$ + + + + \ No newline at end of file diff --git a/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml index bd22a3a..544672f 100644 --- a/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/maven-archetype-simple/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -1,8 +1,10 @@ - + src/main/java @@ -17,4 +19,4 @@ .mvn - + \ No newline at end of file diff --git a/maven-archetype-withparent/pom.xml b/maven-archetype-withparent/pom.xml index 45f7eb4..10eccae 100644 --- a/maven-archetype-withparent/pom.xml +++ b/maven-archetype-withparent/pom.xml @@ -19,4 +19,7 @@ UTF-8 + + maven-help-plugin + diff --git a/maven-archetype-withparent/rules.xml b/maven-archetype-withparent/rules.xml new file mode 100644 index 0000000..92b03f7 --- /dev/null +++ b/maven-archetype-withparent/rules.xml @@ -0,0 +1,16 @@ + + + + + (?i).*Alpha(?:-?\d+)? + (?i).*a(?:-?\d+)? + (?i).*Beta(?:-?\d+)? + (?i).*-B(?:-?\d+)? + (?i).*RC(?:-?\d+)? + (?i).*CR(?:-?\d+)? + (?i).*M(?:-?\d+)? + .*jre[0-9]+$ + + + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml index da445a9..a779335 100644 --- a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -73,9 +73,12 @@ mvnw.cmd rules.xml README.md - + .github + docker + .mvn + - + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml index e68a6e0..69e20e4 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml @@ -3,6 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> + + + maven-proxy + Maven Repository Manager + + https://compute-lsis-2.univ-tln.fr/nexus/repository/maven-public/ + central + + + github @@ -27,6 +37,11 @@ ${env.MAVEN_USERNAME} ${env.MAVEN_CENTRAL_TOKEN} + + maven-proxy + ${env.MAVENPROXY_USERNAME} + ${env.MAVENPROXY_TOKEN} + @@ -40,10 +55,10 @@ github - + github https://maven.pkg.github.com/${env.GITHUBORG}/* @@ -54,10 +69,44 @@ + + + nexus + + + central + http://central + + true + never + + + true + always + + + + + + central + http://central + + true + never + + + true + always + + + + + github + nexus \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml index 7693789..e252817 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml @@ -68,16 +68,6 @@ - - - - - org.apache.maven.plugins - maven-failsafe-plugin - - - - https://github.com/${github.account}/${project.artifactId}/tree/${project.scm.tag} scm:git:git@github.com:${github.account}/${project.artifactId}.git diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java index b1db7c2..5ee3a19 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java @@ -1,6 +1,7 @@ package $package; import lombok.extern.java.Log; +import lombok.experimental.UtilityClass; import java.text.MessageFormat; import java.util.Arrays; @@ -11,7 +12,14 @@ * A simple starting App ready for CI. */ @Log +//@UtilityClass public class App { + + /** + * A default constructor with a comment + */ + public App() { /* TODO complete this dummy constructor */ } + /** * A resource bundle for I18N internationalisation. */ diff --git a/pom.xml b/pom.xml index f1ed3f5..8b4999f 100644 --- a/pom.xml +++ b/pom.xml @@ -67,21 +67,44 @@ + + + + maven-help-plugin + 3.4.0 + + true + ${project.build.directory}/effective-settings.xml + + + + + pre-integration-test + + effective-settings + + + + + org.apache.maven.plugins maven-archetype-plugin - 3.2.0 + 3.2.1 + ${project.build.directory}/effective-settings.xml true - + true + org.codehaus.groovy groovy-xml - 2.4.16 + 3.0.17 From 9bd3364839cacd603a6f2de2dc257abed572f539 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Tue, 23 May 2023 22:55:59 +0200 Subject: [PATCH 12/22] fixes distribution metadata --- maven-archetype-simple/pom.xml | 35 +-------------------------- maven-archetype-withparent/pom.xml | 17 +++++++++---- pom.xml | 39 +++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 40 deletions(-) diff --git a/maven-archetype-simple/pom.xml b/maven-archetype-simple/pom.xml index df0086f..7b76fdf 100644 --- a/maven-archetype-simple/pom.xml +++ b/maven-archetype-simple/pom.xml @@ -6,7 +6,7 @@ fr.ebruno.maven.archetypes - maven-archetype-bundles + maven-archetypes 0.1.0-SNAPSHOT @@ -23,37 +23,4 @@ - - - maven-help-plugin - 2.2 - - ${project.build.directory}/effective-settings.xml - - - - - pre-integration-test - - effective-settings - - - - - - maven-archetype-plugin - 2.4 - - ${project.build.directory}/effective-settings.xml - - - - commons-lang - commons-lang - 2.6 - - - - - diff --git a/maven-archetype-withparent/pom.xml b/maven-archetype-withparent/pom.xml index 10eccae..ece7a73 100644 --- a/maven-archetype-withparent/pom.xml +++ b/maven-archetype-withparent/pom.xml @@ -1,11 +1,13 @@ - + 4.0.0 fr.ebruno.maven.archetypes - maven-archetype-bundles + maven-archetypes 0.1.0-SNAPSHOT @@ -19,7 +21,12 @@ UTF-8 - - maven-help-plugin + + + + maven-help-plugin + + + - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8b4999f..375ea8c 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ fr.ebruno.maven.archetypes - maven-archetype-bundles + maven-archetypes 0.1.0-SNAPSHOT pom @@ -44,6 +44,29 @@ + + https://github.com/${github.account}/${project.artifactId}/tree/${project.scm.tag} + scm:git:git@github.com:${github.account}/${project.artifactId}.git + scm:git:git@github.com:${github.account}/${project.artifactId}.git + + + + + github + GitHub Packages + https://maven.pkg.github.com/${github.account}/${project.artifactId} + + + github + GitHub Packages + https://maven.pkg.github.com/${github.account}/${project.artifactId} + + + githubpages + scm:git:ssh://git@github.com/${github.account}/${project.artifactId}.git + + + @@ -117,5 +140,19 @@ + + + + org.apache.maven.plugins + maven-help-plugin + + + org.apache.maven.plugins + maven-archetype-plugin + + + + + \ No newline at end of file From 1881e28e121fa9788f78499b77339453992bac39 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Wed, 24 May 2023 09:49:36 +0200 Subject: [PATCH 13/22] fixes possible leak during ghpages creation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5c3df5c..b09aa58 100644 --- a/README.md +++ b/README.md @@ -153,7 +153,7 @@ git flow init -d && touch README.md && git add . && git commit -m "sets initial gh repo create ${GITHUBORG}/${PWD##*/} --disable-wiki --private --source=. --push &&\ git checkout --orphan gh-pages && \ git rm -rf . && touch index.html && \ - git add . && \ + git add index.html && \ git commit -m "sets initial empty site." && \ git push --all \ && git checkout develop &&\ From cec06de98478107880468c9c6ca3f40a0c87d4db Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Wed, 24 May 2023 11:50:26 +0200 Subject: [PATCH 14/22] fixes maven proxy --- README.md | 6 +++--- ci-settings.xml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b09aa58..cac64ed 100644 --- a/README.md +++ b/README.md @@ -84,16 +84,16 @@ java -jar target/MyApp-0.1.0-SNAPSHOT.jar This project generates a complete Java+Maven project ready for Continuous Integration (CI). It is ready for GitFlow, SonarQube (tests, code coverage, ...). -It can produce signed artifacts, fat jars, slim runtime with jLink, native executables with GraalVM +It can produce signed artifacts, fat jars, slim runtime with jLink, native executables with GraalVM and container images. The build itself can also be done in a container. ### Configuration (Once) The configuration is done with environment variables. For GitHub : GITHUBORG (GitHub account or organisation), GITHUBACTOR, GITHUBTOKEN, GITHUBORG (org or account) -and optionally for SonarQube SONAR_URL and SONAR_TOKEN (To install SonarQube see https://github.com/ebpro/sonarqube) +and optionally for SonarQube SONAR_URL and SONAR_TOKEN (Needs an instance of [SonarQube](https://github.com/ebpro/sonarqube)) -For GitHub the CLI is needed (https://cli.github.com/). +For GitHub the [CLI](https://cli.github.com/) is needed. Those variables have to be stored on the CI server (see [GitHub Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)). The script below transforms the local variables in GitHub secrets. diff --git a/ci-settings.xml b/ci-settings.xml index 8450a01..2ebb14f 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -3,14 +3,14 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> - + @@ -100,7 +100,7 @@ github - + nexus \ No newline at end of file From e9077ff9db4be66b50ef5c45f9a5c6e1d1df1ae1 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Wed, 24 May 2023 22:05:28 +0200 Subject: [PATCH 15/22] fixes site --- ci-settings.xml | 4 +- .../src/site/markdown/README.md.vm | 4 +- maven-archetype-simple/src/site/site.xml | 69 +++- .../archetype-resources/ci-settings.xml | 12 +- .../src/site/markdown/README.md.vm | 2 + .../src/site/markdown/README.md.vm | 1 + maven-archetype-withparent/src/site/site.xml | 45 ++- src/site/markdown/README.md.vm | 370 ++++++++++++++++++ src/site/site.xml | 92 +++-- src/site/xdoc/download.xml.vm | 126 ------ 10 files changed, 534 insertions(+), 191 deletions(-) create mode 100644 src/site/markdown/README.md.vm delete mode 100644 src/site/xdoc/download.xml.vm diff --git a/ci-settings.xml b/ci-settings.xml index 2ebb14f..c3ae79e 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -1,7 +1,7 @@ - + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> diff --git a/maven-archetype-simple/src/site/markdown/README.md.vm b/maven-archetype-simple/src/site/markdown/README.md.vm index b0aeaa7..94265f8 100644 --- a/maven-archetype-simple/src/site/markdown/README.md.vm +++ b/maven-archetype-simple/src/site/markdown/README.md.vm @@ -1,6 +1,6 @@ # ${project.name} - <<<${project.artifactId}>>> is an archetype which generates a simple Maven project: +${project.groupId}:${project.artifactId}:${project.version} is an archetype which generates a simple Maven project: ## Usage @@ -21,7 +21,7 @@ mvn archetype:generate \ -DarchetypeArtifactId=maven-archetype-simple \ -DgroupId=demo.pkg \ -DartifactId=MyAppHelloWorld \ - -Dversion=1.0-SNAPSHOT + -Dversion=0.1.0-SNAPSHOT ``` The result can be compiled with maven diff --git a/maven-archetype-simple/src/site/site.xml b/maven-archetype-simple/src/site/site.xml index 493406e..c33d516 100644 --- a/maven-archetype-simple/src/site/site.xml +++ b/maven-archetype-simple/src/site/site.xml @@ -1,8 +1,67 @@ + - - - - + + + + + + + + + + ${project.scm.url} + + + + + + + + + + + + + + + + + + pre-release + false + true + true + + ${project.url} + + pull-right + + ${github.account}/${project.artifactId}/ + right + gray + + » + + + + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml index 69e20e4..c3ae79e 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/ci-settings.xml @@ -1,13 +1,12 @@ - + xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd"> maven-proxy Maven Repository Manager - https://compute-lsis-2.univ-tln.fr/nexus/repository/maven-public/ central @@ -55,10 +54,6 @@ github - github https://maven.pkg.github.com/${env.GITHUBORG}/* @@ -70,8 +65,7 @@ - - nexus + nexus central diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm index 20360dc..0a106fd 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/markdown/README.md.vm @@ -1,8 +1,10 @@ # Usage + This simple Java Project is ready for Continuous Integration (CI). The application can simply be packaged without and with dependencies. The default main class of the manifest is defined (see pom.xml). + ```console # Compile, run unit and integration tests (the shade plugin generate two artifacts) and package. mvn verify diff --git a/maven-archetype-withparent/src/site/markdown/README.md.vm b/maven-archetype-withparent/src/site/markdown/README.md.vm index 2ce6673..91bec39 100644 --- a/maven-archetype-withparent/src/site/markdown/README.md.vm +++ b/maven-archetype-withparent/src/site/markdown/README.md.vm @@ -1,4 +1,5 @@ # Usage + This archetype can create a simple Java Project ready for Continuous Integration (CI). Set your `-DgithubAccount=` and change `-DgroupId` and `-DartifactId` to match the new application ones. diff --git a/maven-archetype-withparent/src/site/site.xml b/maven-archetype-withparent/src/site/site.xml index 2905986..82836eb 100644 --- a/maven-archetype-withparent/src/site/site.xml +++ b/maven-archetype-withparent/src/site/site.xml @@ -1,9 +1,8 @@ - - - org.apache.maven.skins - maven-fluido-skin - 1.9 - + + - + + ${project.scm.url} + + + + + + + + - - + - - + + pre-release false true true ${project.url} + pull-right ${github.account}/${project.artifactId}/ right gray + » - + + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + + \ No newline at end of file diff --git a/src/site/markdown/README.md.vm b/src/site/markdown/README.md.vm new file mode 100644 index 0000000..558f974 --- /dev/null +++ b/src/site/markdown/README.md.vm @@ -0,0 +1,370 @@ +# Best practices Maven archetypes + +This project maintains some Maven archetypes. + +* `fr.ebruno.maven.archetypes:simple` a simple standalone Java project. +* `fr.ebruno.maven.archetypes:simple-withparent`a CI ready one with a complete parent POM. + +## fr.ebruno.maven.archetypes:simple + +An archetype to generate a simple standalone maven project. + +### Usage + +To generate from the archetype : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-simple +``` + +parameters can be passed directly : + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-simple \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +The result can be compiled with maven + +```console +cd MyApp +mvn verify +``` + +and executed with maven : + +```console +mvn exec:java -Dexec.mainClass="demo.pkg.App" +``` + +or with java (beware no dependencies in the slim jar) + +```console +cd MyAppHelloWorld +java -cp target/MyAppHelloWorld-1.0-SNAPSHOT.jar demo.pkg.App +``` + +### Web site + +a web site can be generated in `target/site/index.html` with : + +```console +mvn site +``` + +## fr.ebruno.maven.archetypes:simple-withparent + +```bash +mvn archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-withparent \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +A parent pom is defined. +By default the jar is "runnable" (see `app.main.class` in `pom.xml`) + +```bash +cd Myapp +mvn verify +java -jar target/MyApp-0.1.0-SNAPSHOT.jar +``` + +## A full git+maven+docker example + +> **WARNING**: STILL WORK IN PROGESS + +This project generates a complete Java+Maven project ready for Continuous Integration (CI). +It is ready for GitFlow, SonarQube (tests, code coverage, ...). +It can produce signed artifacts, fat jars, slim runtime with jLink, native executables with GraalVM +and container images. The build itself can also be done in a container. + +### Configuration (Once) + +The configuration is done with environment variables. +For GitHub : GITHUBORG (GitHub account or organisation), GITHUBACTOR, GITHUBTOKEN, GITHUBORG (org or account) +and optionally for SonarQube SONAR_URL and SONAR_TOKEN (Needs an instance of [SonarQube](https://github.com/ebpro/sonarqube)) + +For GitHub the [CLI](https://cli.github.com/) is needed. + +Those variables have to be stored on the CI server (see [GitHub Encrypted secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets)). +The script below transforms the local variables in GitHub secrets. + +```bash +bash -c 'for secret in GITHUBACTOR GITHUBTOKEN SONAR_URL SONAR_TOKEN; do \ +eval gh secret set $secret --app actions \ + --body ${!secret} \ + --org ${GITHUBORG} \ + --visibility all; \ +done' +``` + +## Each new project + +> **NOTE**: Short version, a wrapper script is provided (READ IT BEFORE USE). + +```bash +source <(curl -s https://raw.githubusercontent.com/ebpro/demomavenarchetype/develop/src/main/resources/archetype-resources/ci-wrappers.sh) +new-java-project +``` + +### Creation + +Generate each new project with this maven archetype (adapt at least the bold parameters). + +```bash +mvn --batch-mode archetype:generate \ + -DarchetypeGroupId=fr.ebruno.maven.archetypes \ + -DarchetypeArtifactId=maven-archetype-withparent \ + -DgithubAccount=$GITHUBORG \ + -DgroupId=demo.pkg \ + -DartifactId=MyApp \ + -Dversion=0.1.0-SNAPSHOT +``` + +To enable deployment in the repo during the CI a deployment key is needed for each repository. + +```bash +tmpKeydir=$(mktemp --directory /tmp/ci-wrappers.XXXXXX) +ssh-keygen -q -t ed25519 -C "An autogenerated deploy key" -N "" -f ${tmpKeydir}/key +gh repo deploy-key add --allow-write "${tmpKeydir}/key.pub" +gh secret set SECRET_DEPLOY_KEY < "${tmpKeydir}/key" +rm -rf tmpKeydir +``` + +### GitFlow + +1. Initialize git environment for GitFlow (develop and master branches). +2. Make a first commit. +3. Create the GitHub repository with the [GitHub Command line Interface](https://cli.github.com/). +4. Create an orphan gh-pages branch for the website. +5. Open the repository in a web browser. + +```bash +#[[ +git flow init -d && touch README.md && git add . && git commit -m "sets initial release." && \ + gh repo create ${GITHUBORG}/${PWD##*/} --disable-wiki --private --source=. --push && \ + git checkout --orphan gh-pages && \ + git rm -rf . && touch index.html && \ + git add index.html && \ + git commit -m "sets initial empty site." && \ + git push --all \ + && git checkout develop && \ + gh repo view --web +]]# +``` + +The project uses the [gitflow-maven-plugin](https://aleksandr-m.github.io/gitflow-maven-plugin) to manage GitFlow for java+Maven projet (branches and artifact version). + +It is possible to easily start and finish a feature (see version in pom.xml). + +```bash +mvn -B gitflow:feature-start -DpushRemote=true -DfeatureName=UI +mvn -B gitflow:feature-start -DpushRemote=true -DfeatureName=DB + +mvn -B gitflow:feature-finish -DpushRemote=true -DfeatureName=DB +mvn -B gitflow:feature-finish -DpushRemote=true -DfeatureName=UI +``` + +```bash +mvn -B gitflow:release-start -DpushRemote=true -DallowSnapshots=true -DuseSnapshotInRelease=true +mvn -B gitflow:release-finish -DpushRemote=true -DallowSnapshots=true +``` + +## Artefact packaging + +### Compilation and execution + +You can compile and package with unit tests. + +```bash +mvn package +``` + +You can compile and package with unit tests and integration tests. + +```bash +mvn verify +``` + +You can execute with maven (see app.mainClass property in pom.xml). + +```bash +mvn exec:java +``` + +### Shaded Jar (close to FatJar or UberJar) + +The profile `shadedjar` generates a fat jar with all the classes from the transitive dependencies. + +```bash +mvn -Pshadedjar clean verify +ls -lh target/*.jar +``` + +```console +-rw-r--r--@ 1 bruno wheel 3.1K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-sources.jar +-rw-r--r--@ 1 bruno wheel 2.6K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-test-sources.jar +-rw-r--r--@ 1 bruno wheel 38K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT-withdependencies.jar +-rw-r--r--@ 1 bruno wheel 4.2K May 20 16:09 target/MyApp-0.1.0-UI-SNAPSHOT.jar +``` + +The application can then be executed without maven : + +```bash +java -jar target/*-withdependencies.jar +``` + +### Jlink + +Thanks to Jlink and a modular java project (jigsaw), it is possible to generate a minimal JRE with needed modules and dependencies. + +```bash +mvn -Pjlink clean verify +du -hs target/image +``` + +```console + 44M target/image + ``` + +The application can then be launched without a JRE installed. + +```bash +./target/image/bin/myapp +``` + +```console +Dec 02, 2022 11:18:56 PM fr.univtln.bruno.demos.App main +INFOS: Hello World! [] +``` + +### GraalVM + +It is also possible to generate a native binary with [GraalVM](https://www.graalvm.org/). An installation of GraalVM is needed and the package build-essential libz-dev and zlib1g-dev (zlib-devel, zlib-static et glibc-static). Only tested in linux. + +```bash +sdk install java 22.3.r19-grl +sdk use java 22.3.r19-grl +``` + +```bash +mvn -Pnative clean verify +ls -lh target/testci +``` + +```console +-rwxr-xr-x 1 bruno users 13M 3 déc. 00:12 target/testci +``` + +```console +./target/testci +déc. 03, 2022 12:15:25 AM fr.univtln.bruno.demos.App main +INFO: Hello World! [] +``` + +### Building with Maven in docker + +It is possible to build and run the project with just docker installed. A wrapper to run maven and java +in a container but to work with the current directory is proposed. ~/.m2, ~/.ssh, ~/.gitconfig and the src directories are mounted. +The environment variables needed for the project are also transmitted. The UID and GID are the one of the current user. + +```bash +docker-mvn clean -P shadedjar package +docker run --rm \ + --mount type=bind,source="$(PWD)"/target/,target=/app,readonly \ + eclipse-temurin:17-jre-alpine \ + sh -c "java -jar /app/*-withdependencies.jar" +``` + +### Docker Multistage build + +The file `docker\Dockerfile` is a multistage Dockerfile to build and deliver the application with several strategies (shaded jar, jlink, GraalVM) on several distributions (debian and alpine). To ease the use a wrapper for docker commands is provided in dockerw.sh + +```bash +. ./ci-wrappers.sh +docker-wrapper-build +docker-wrapper-run +``` + +It is also possible to build all final target (Warning graalvm takes a long time to compile). + +```bash +docker-wrapper-build-all +``` + +the result show the images and their size. + +```bash +ebpro/testci develop-finalShadedjarDebian af3e072b35f7 2 hours ago 266MB +ebpro/testci develop-finalShadedjarAlpine 38973a2aa588 2 hours ago 170MB +ebpro/testci develop-finaljLinkDebian db847ca5b281 2 hours ago 133MB +ebpro/testci develop-finalJLinkAlpine 0cba42a81a33 2 hours ago 58.2MB +ebpro/testci develop-finalGraalvmDebian f5607a1e055f 2 hours ago 93.7MB +ebpro/testci develop-finalGraalvmAlpine d9c0573e4750 2 hours ago 18.8MB +``` + +It is also possible to run all the images : + +```bash +docker-wrapper-run-all +``` + +```log +INFO: Hello World! [] + 0,06s user 0,04s system 6% cpu 1,529 total +Running ebpro/testci:develop-finalShadedjarAlpine +Dec 05, 2022 4:37:06 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,05s system 5% cpu 1,724 total +Running ebpro/testci:develop-finaljLinkDebian +Dec 05, 2022 4:37:07 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,05s system 5% cpu 1,690 total +Running ebpro/testci:develop-finalJLinkAlpine +Dec 05, 2022 4:37:09 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,04s user 0,05s system 5% cpu 1,723 total +Running ebpro/testci:develop-finalGraalvmDebian +Dec 05, 2022 4:37:10 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] + 0,05s user 0,03s system 7% cpu 1,161 total +Running ebpro/testci:develop-finalGraalvmAlpine +Dec 05, 2022 4:37:12 PM fr.univtln.bruno.demos.App main +INFO: Hello World! [] +``` + +### Quality + +If a sonarqube server is available (i.e with https://github.com/ebpro/sonarqube). +Set the variable SONAR_URL and SONAR_TOKEN + +```bash +mvn -P jacoco,sonar \ + -Dsonar.branch.name=$(git rev-parse --abbrev-ref HEAD | tr / _) \ + verify sonar:sonar +``` + +### TODO: FIX LOST CODE COVERAGE + +```bash +mvn clean verify +mvn -DskipTests=true \ + -Dsonar.branch.name=$(git rev-parse --abbrev-ref HEAD | tr / _) \ + -P jacoco,sonar \ + sonar:sonar +``` + +### Web site + +```bash +mvn site:site +``` \ No newline at end of file diff --git a/src/site/site.xml b/src/site/site.xml index 8cf6437..c33d516 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,41 +1,67 @@ + - + + + - + + + + - ${project.scm.url} + ${project.scm.url} - - - - + + + + - - - - - - + + + + + + + + + + + + pre-release + false + true + true + + ${project.url} + + pull-right + + ${github.account}/${project.artifactId}/ + right + gray + + » + + - - + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + \ No newline at end of file diff --git a/src/site/xdoc/download.xml.vm b/src/site/xdoc/download.xml.vm deleted file mode 100644 index 9f1ef1a..0000000 --- a/src/site/xdoc/download.xml.vm +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - Download ${project.name} Source - - -
- -

${project.name} ${project.version} is distributed in source format. Use a source archive if you intend to build - ${project.name} yourself. Otherwise, simply use the ready-made binary artifacts from central repository.

- -

You will be prompted for a mirror - if the file is not found on yours, please be patient, as it may take 24 - hours to reach all mirrors.

- -

In order to guard against corrupted downloads/installations, it is highly recommended to - verify the signature - of the release bundles against the public KEYS used by the Apache Maven - developers.

- -

${project.name} is distributed under the Apache License, version 2.0.

- -

We strongly encourage our users to configure a Maven repository mirror closer to their location, please read How to Use Mirrors for Repositories.

- - - - -

- [if-any logo] - - logo - - [end] - The currently selected mirror is - [preferred]. - If you encounter a problem with this mirror, - please select another mirror. - If all mirrors are failing, there are - backup - mirrors - (at the end of the mirrors list) that should be available. -

- -
- Other mirrors: - - -
- -

- You may also consult the - complete list of - mirrors. -

- - - - - -

This is the current stable version of ${project.name}.

- - - - - - - - - - - - - - - - - - -
LinkChecksumSignature
${project.name} ${project.version} (Source zip)maven/archetype/${project.artifactId}-${project.version}-source-release.zipmaven/archetype/${project.artifactId}-${project.version}-source-release.zip.sha512maven/archetype/${project.artifactId}-${project.version}-source-release.zip.asc
-
- - - -

Older non-recommended releases can be found on our archive site.

- -
-
- -
- From 061fb014b93b2d16d98a6a8961406a86d544b17d Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Thu, 25 May 2023 18:45:33 +0200 Subject: [PATCH 16/22] fixes full archetype --- README.md | 7 +- .../META-INF/maven/archetype-metadata.xml | 24 +- .../main/resources/archetype-resources/mvnw | 287 ------------------ .../resources/archetype-resources/mvnw.cmd | 187 ------------ .../resources/archetype-resources/pom.xml | 25 +- .../src/main/java/App.java | 6 +- .../src/main/java/module-info.java | 3 +- .../src/main/resources/demoI18N_fr.properties | 2 +- .../src/main/resources/logback.xml | 17 ++ .../archetype-resources/src/site/site.xml | 41 ++- maven-archetype-withparent/src/site/site.xml | 5 +- pom.xml | 14 +- src/site/markdown/README.md.vm | 47 ++- 13 files changed, 128 insertions(+), 537 deletions(-) delete mode 100755 maven-archetype-withparent/src/main/resources/archetype-resources/mvnw delete mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/logback.xml diff --git a/README.md b/README.md index cac64ed..fc43f89 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ INFO: Hello World! [] ### Building with Maven in docker It is possible to build and run the project with just docker installed. A wrapper to run maven and java -in a container but to work with the current directory is proposed. ~/.m2, ~/.ssh, ~/.gitconfig and the src directories are mounted. +in a container but to work with the current directory is proposed. ~/.m2, ~/.ssh, ~/.gitconfig and the src directories are mounted. The environment variables needed for the project are also transmitted. The UID and GID are the one of the current user. ```bash @@ -285,10 +285,7 @@ docker run --rm \ ### Docker Multistage build -The file `docker\Dockerfile` is a multistage Dockerfile to build and deliver -the application with several strategies (shaded jar, jlink, GraalVM) -on several distributions (debian and alpine). -To ease the use a wrapper for docker commands is provided in dockerw.sh +The file `docker\Dockerfile` is a multistage Dockerfile to build and deliver the application with several strategies (shaded jar, jlink, GraalVM) on several distributions (debian and alpine). To ease the use a wrapper for docker commands is provided in dockerw.sh ```bash . ./ci-wrappers.sh diff --git a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml index a779335..628d67d 100644 --- a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -7,13 +7,13 @@ name="${artifactId}"> - - + src/main/java + **/*.java @@ -69,24 +69,14 @@ .dockerignore .gitignore.template wrappers.sh - mvnw - mvnw.cmd + ci-settings.xml rules.xml README.md - .github - docker - .mvn - - - \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw deleted file mode 100755 index b7f0646..0000000 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw +++ /dev/null @@ -1,287 +0,0 @@ -#!/bin/sh -# ---------------------------------------------------------------------------- -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -# ---------------------------------------------------------------------------- - -# ---------------------------------------------------------------------------- -# Apache Maven Wrapper startup batch script, version 3.1.1 -# -# Required ENV vars: -# ------------------ -# JAVA_HOME - location of a JDK home dir -# -# Optional ENV vars -# ----------------- -# MAVEN_OPTS - parameters passed to the Java VM when running Maven -# e.g. to debug Maven itself, use -# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -# MAVEN_SKIP_RC - flag to disable loading of mavenrc files -# ---------------------------------------------------------------------------- - -if [ -z "$MAVEN_SKIP_RC" ] ; then - - if [ -f /usr/local/etc/mavenrc ] ; then - . /usr/local/etc/mavenrc - fi - - if [ -f /etc/mavenrc ] ; then - . /etc/mavenrc - fi - - if [ -f "$HOME/.mavenrc" ] ; then - . "$HOME/.mavenrc" - fi - -fi - -# OS specific support. $var _must_ be set to either true or false. -cygwin=false; -darwin=false; -mingw=false -case "`uname`" in - CYGWIN*) cygwin=true ;; - MINGW*) mingw=true;; - Darwin*) darwin=true - # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home - # See https://developer.apple.com/library/mac/qa/qa1170/_index.html - if [ -z "$JAVA_HOME" ]; then - if [ -x "/usr/libexec/java_home" ]; then - JAVA_HOME="`/usr/libexec/java_home`"; export JAVA_HOME - else - JAVA_HOME="/Library/Java/Home"; export JAVA_HOME - fi - fi - ;; -esac - -if [ -z "$JAVA_HOME" ] ; then - if [ -r /etc/gentoo-release ] ; then - JAVA_HOME=`java-config --jre-home` - fi -fi - -# For Cygwin, ensure paths are in UNIX format before anything is touched -if $cygwin ; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --unix "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --unix "$CLASSPATH"` -fi - -# For Mingw, ensure paths are in UNIX format before anything is touched -if $mingw ; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" -fi - -if [ -z "$JAVA_HOME" ]; then - javaExecutable="`which javac`" - if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then - # readlink(1) is not available as standard on Solaris 10. - readLink=`which readlink` - if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then - if $darwin ; then - javaHome="`dirname \"$javaExecutable\"`" - javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" - else - javaExecutable="`readlink -f \"$javaExecutable\"`" - fi - javaHome="`dirname \"$javaExecutable\"`" - javaHome=`expr "$javaHome" : '\(.*\)/bin'` - JAVA_HOME="$javaHome" - export JAVA_HOME - fi - fi -fi - -if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - if [ -x "$JAVA_HOME/jre/sh/java" ] ; then - # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" - else - JAVACMD="$JAVA_HOME/bin/java" - fi - else - JAVACMD="`\\unset -f command; \\command -v java`" - fi -fi - -if [ ! -x "$JAVACMD" ] ; then - echo "Error: JAVA_HOME is not defined correctly." >&2 - echo " We cannot execute $JAVACMD" >&2 - exit 1 -fi - -if [ -z "$JAVA_HOME" ] ; then - echo "Warning: JAVA_HOME environment variable is not set." -fi - -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { - if [ -z "$1" ] - then - echo "Path not specified to find_maven_basedir" - return 1 - fi - - basedir="$1" - wdir="$1" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - # workaround for JBEAP-8937 (on Solaris 10/Sparc) - if [ -d "${wdir}" ]; then - wdir=`cd "$wdir/.."; pwd` - fi - # end of workaround - done - printf '%s' "$(cd "$basedir"; pwd)" -} - -# concatenates all lines of a file -concat_lines() { - if [ -f "$1" ]; then - echo "$(tr -s '\n' ' ' < "$1")" - fi -} - -BASE_DIR=$(find_maven_basedir "$(dirname $0)") -if [ -z "$BASE_DIR" ]; then - exit 1; -fi - -MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"}; export MAVEN_PROJECTBASEDIR -if [ "$MVNW_VERBOSE" = true ]; then - echo $MAVEN_PROJECTBASEDIR -fi - -########################################################################################## -# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -# This allows using the maven wrapper in projects that prohibit checking in binary data. -########################################################################################## -if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found .mvn/wrapper/maven-wrapper.jar" - fi -else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." - fi - if [ -n "$MVNW_REPOURL" ]; then - wrapperUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" - else - wrapperUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" - fi - while IFS="=" read key value; do - case "$key" in (wrapperUrl) wrapperUrl="$value"; break ;; - esac - done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Downloading from: $wrapperUrl" - fi - wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" - if $cygwin; then - wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` - fi - - if command -v wget > /dev/null; then - QUIET="--quiet" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found wget ... using wget" - QUIET="" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - wget $QUIET "$wrapperUrl" -O "$wrapperJarPath" - else - wget $QUIET --http-user="$MVNW_USERNAME" --http-password="$MVNW_PASSWORD" "$wrapperUrl" -O "$wrapperJarPath" - fi - [ $? -eq 0 ] || rm -f "$wrapperJarPath" - elif command -v curl > /dev/null; then - QUIET="--silent" - if [ "$MVNW_VERBOSE" = true ]; then - echo "Found curl ... using curl" - QUIET="" - fi - if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then - curl $QUIET -o "$wrapperJarPath" "$wrapperUrl" -f -L - else - curl $QUIET --user "$MVNW_USERNAME:$MVNW_PASSWORD" -o "$wrapperJarPath" "$wrapperUrl" -f -L - fi - [ $? -eq 0 ] || rm -f "$wrapperJarPath" - else - if [ "$MVNW_VERBOSE" = true ]; then - echo "Falling back to using Java to download" - fi - javaSource="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" - javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" - # For Cygwin, switch paths to Windows format before running javac - if $cygwin; then - javaSource=`cygpath --path --windows "$javaSource"` - javaClass=`cygpath --path --windows "$javaClass"` - fi - if [ -e "$javaSource" ]; then - if [ ! -e "$javaClass" ]; then - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Compiling MavenWrapperDownloader.java ..." - fi - # Compiling the Java class - ("$JAVA_HOME/bin/javac" "$javaSource") - fi - if [ -e "$javaClass" ]; then - # Running the downloader - if [ "$MVNW_VERBOSE" = true ]; then - echo " - Running MavenWrapperDownloader.java ..." - fi - ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") - fi - fi - fi -fi -########################################################################################## -# End of extension -########################################################################################## - -MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" - -# For Cygwin, switch paths to Windows format before running java -if $cygwin; then - [ -n "$JAVA_HOME" ] && - JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` - [ -n "$CLASSPATH" ] && - CLASSPATH=`cygpath --path --windows "$CLASSPATH"` - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -# Provide a "standardized" way to retrieve the CLI args that will -# work with both Windows and non-Windows executions. -MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" -export MAVEN_CMD_LINE_ARGS - -WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -exec "$JAVACMD" \ - $MAVEN_OPTS \ - $MAVEN_DEBUG_OPTS \ - -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ - "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ - ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd b/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd deleted file mode 100644 index cba1f04..0000000 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/mvnw.cmd +++ /dev/null @@ -1,187 +0,0 @@ -@REM ---------------------------------------------------------------------------- -@REM Licensed to the Apache Software Foundation (ASF) under one -@REM or more contributor license agreements. See the NOTICE file -@REM distributed with this work for additional information -@REM regarding copyright ownership. The ASF licenses this file -@REM to you under the Apache License, Version 2.0 (the -@REM "License"); you may not use this file except in compliance -@REM with the License. You may obtain a copy of the License at -@REM -@REM http://www.apache.org/licenses/LICENSE-2.0 -@REM -@REM Unless required by applicable law or agreed to in writing, -@REM software distributed under the License is distributed on an -@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@REM KIND, either express or implied. See the License for the -@REM specific language governing permissions and limitations -@REM under the License. -@REM ---------------------------------------------------------------------------- - -@REM ---------------------------------------------------------------------------- -@REM Apache Maven Wrapper startup batch script, version 3.1.1 -@REM -@REM Required ENV vars: -@REM JAVA_HOME - location of a JDK home dir -@REM -@REM Optional ENV vars -@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands -@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending -@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven -@REM e.g. to debug Maven itself, use -@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 -@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files -@REM ---------------------------------------------------------------------------- - -@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' -@echo off -@REM set title of command window -title %0 -@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' -@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% - -@REM set %HOME% to equivalent of $HOME -if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") - -@REM Execute a user defined script before this one -if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre -@REM check for pre script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* -if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* -:skipRcPre - -@setlocal - -set ERROR_CODE=0 - -@REM To isolate internal variables from possible post scripts, we use another setlocal -@setlocal - -@REM ==== START VALIDATION ==== -if not "%JAVA_HOME%" == "" goto OkJHome - -echo. -echo Error: JAVA_HOME not found in your environment. >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -:OkJHome -if exist "%JAVA_HOME%\bin\java.exe" goto init - -echo. -echo Error: JAVA_HOME is set to an invalid directory. >&2 -echo JAVA_HOME = "%JAVA_HOME%" >&2 -echo Please set the JAVA_HOME variable in your environment to match the >&2 -echo location of your Java installation. >&2 -echo. -goto error - -@REM ==== END VALIDATION ==== - -:init - -@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% -IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set EXEC_DIR=%CD% -set WDIR=%EXEC_DIR% -:findBaseDir -IF EXIST "%WDIR%"\.mvn goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set WDIR=%CD% -goto findBaseDir - -:baseDirFound -set MAVEN_PROJECTBASEDIR=%WDIR% -cd "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -set MAVEN_PROJECTBASEDIR=%EXEC_DIR% -cd "%EXEC_DIR%" - -:endDetectBaseDir - -IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig - -@setlocal EnableExtensions EnableDelayedExpansion -for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a -@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% - -:endReadAdditionalConfig - -SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" -set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" -set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain - -set WRAPPER_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" - -FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( - IF "%%A"=="wrapperUrl" SET WRAPPER_URL=%%B -) - -@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central -@REM This allows using the maven wrapper in projects that prohibit checking in binary data. -if exist %WRAPPER_JAR% ( - if "%MVNW_VERBOSE%" == "true" ( - echo Found %WRAPPER_JAR% - ) -) else ( - if not "%MVNW_REPOURL%" == "" ( - SET WRAPPER_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar" - ) - if "%MVNW_VERBOSE%" == "true" ( - echo Couldn't find %WRAPPER_JAR%, downloading it ... - echo Downloading from: %WRAPPER_URL% - ) - - powershell -Command "&{"^ - "$webclient = new-object System.Net.WebClient;"^ - "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ - "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ - "}"^ - "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%WRAPPER_URL%', '%WRAPPER_JAR%')"^ - "}" - if "%MVNW_VERBOSE%" == "true" ( - echo Finished downloading %WRAPPER_JAR% - ) -) -@REM End of extension - -@REM Provide a "standardized" way to retrieve the CLI args that will -@REM work with both Windows and non-Windows executions. -set MAVEN_CMD_LINE_ARGS=%* - -%MAVEN_JAVA_EXE% ^ - %JVM_CONFIG_MAVEN_PROPS% ^ - %MAVEN_OPTS% ^ - %MAVEN_DEBUG_OPTS% ^ - -classpath %WRAPPER_JAR% ^ - "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ - %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* -if ERRORLEVEL 1 goto error -goto end - -:error -set ERROR_CODE=1 - -:end -@endlocal & set ERROR_CODE=%ERROR_CODE% - -if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost -@REM check for post script, once with legacy .bat ending and once with .cmd ending -if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" -if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" -:skipRcPost - -@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' -if "%MAVEN_BATCH_PAUSE%"=="on" pause - -if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% - -cmd /C exit /B %ERROR_CODE% diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml index e252817..6f9e757 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml @@ -16,22 +16,27 @@ ${package}.App + + ${githubAccount} - ${artifactId} + A quickstart Java project 2022 + + + + + + + org.junit.jupiter + junit-jupiter-api + test + org.junit.jupiter junit-jupiter-engine + test + + org.slf4j + slf4j-api + ch.qos.logback logback-classic diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java index 5ee3a19..434ac29 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java @@ -1,7 +1,6 @@ package $package; -import lombok.extern.java.Log; -import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; import java.text.MessageFormat; import java.util.Arrays; @@ -11,8 +10,7 @@ /** * A simple starting App ready for CI. */ -@Log -//@UtilityClass +@Slf4j public class App { /** diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java index 198895d..daead9a 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java @@ -2,7 +2,8 @@ * A simple jigsaw module */ module $package.$artifactId { - requires java.logging; + requires org.slf4j; + requires ch.qos.logback.classic; requires static lombok; exports $package; diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties index f13b573..e822603 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/demoI18N_fr.properties @@ -1,2 +1,2 @@ helloworld=Bonjour à tous ! -parameter.format.positive=Parameter has to be positive. +parameter.format.positive=Le paramètre doit être positif. diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/logback.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/logback.xml new file mode 100644 index 0000000..958569e --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/resources/logback.xml @@ -0,0 +1,17 @@ + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} -%kvp- %msg%n + + + + + + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml index ca5eb57..c33d516 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/site/site.xml @@ -1,9 +1,8 @@ - - - org.apache.maven.skins - maven-fluido-skin - 1.11.2 - + + + + ${project.scm.url} + + + + + + + - - - + - - - true - false + + pre-release + false + true true ${project.url} @@ -51,4 +57,11 @@ » - + + + org.apache.maven.skins + maven-fluido-skin + 1.11.2 + + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/site/site.xml b/maven-archetype-withparent/src/site/site.xml index 82836eb..c33d516 100644 --- a/maven-archetype-withparent/src/site/site.xml +++ b/maven-archetype-withparent/src/site/site.xml @@ -27,14 +27,13 @@ - + - + - diff --git a/pom.xml b/pom.xml index 375ea8c..b34903d 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,9 @@ ebpro UTF-8 - archetypes-archives/archetypes-LATEST + + 3.2.0 + @@ -61,10 +63,12 @@ GitHub Packages https://maven.pkg.github.com/${github.account}/${project.artifactId} + githubpages scm:git:ssh://git@github.com/${github.account}/${project.artifactId}.git + @@ -72,7 +76,7 @@ org.apache.maven.archetype archetype-packaging - 3.2.0 + ${mavenarchetypepackaging.version} @@ -94,7 +98,6 @@ maven-help-plugin - 3.4.0 true ${project.build.directory}/effective-settings.xml @@ -113,15 +116,10 @@ org.apache.maven.plugins maven-archetype-plugin - 3.2.1 ${project.build.directory}/effective-settings.xml true true - diff --git a/src/site/markdown/README.md.vm b/src/site/markdown/README.md.vm index 558f974..c793b05 100644 --- a/src/site/markdown/README.md.vm +++ b/src/site/markdown/README.md.vm @@ -30,24 +30,61 @@ mvn archetype:generate \ -Dversion=0.1.0-SNAPSHOT ``` +In in the project directory, a maven wrapper should be generated to control Maven version for this project. + +```bash +cd MyApp +mvn wrapper:wrapper +``` + The result can be compiled with maven ```console cd MyApp -mvn verify +./mvnw verify ``` and executed with maven : ```console -mvn exec:java -Dexec.mainClass="demo.pkg.App" +./mvnw exec:java -Dexec.mainClass="demo.pkg.App" +``` + +but as the default `App` class is defined in a property in the ``pom.xml`, this could be simply : + +```console +./mvnw exec:java" +``` + +The jar can be launch with java but the slim jar fails because of missing dependencies. + +```console +java -cp target/MyApp-0.1.0-SNAPSHOT.jar demo.pkg.App +java -jar target/MyApp-0.1.0-SNAPSHOT.jar ``` -or with java (beware no dependencies in the slim jar) +A complete packaging (javadoc jar and shadedjar) can be done with : + +```console +./mvnw --activate-profiles javadoc,shadedjar verify +``` ```console -cd MyAppHelloWorld -java -cp target/MyAppHelloWorld-1.0-SNAPSHOT.jar demo.pkg.App +java -cp target/MyApp-0.1.0-SNAPSHOT-withdependencies.jar demo.pkg.App +java -jar target/MyApp-0.1.0-SNAPSHOT-withdependencies.jar +``` + +Thanks to Jlink and a modular java project (jigsaw), it is possible to generate a minimal JRE with needed modules and dependencies. + +```bash +./mvnw --activate-profiles javadoc,jlink clean verify +du -hs target/image +``` + +It is interesting to compare sizes of the shaded jar, the Jlink distribution (with an embeded JRE) +```bash +du -hs target/*-withdependencies.jar +du -hs target/image ``` ### Web site From 3dc1a3f87c2860a993536acc227d5fdf40bd35ae Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Thu, 25 May 2023 19:26:03 +0200 Subject: [PATCH 17/22] cleans up java CI --- .github/workflows/ci.yml | 3 + .../.github/workflows-advanced/ci.yml | 11 --- .../.github/workflows/CI-java.yml | 14 ++++ .../.github/workflows/basic-java.yml | 77 ------------------- 4 files changed, 17 insertions(+), 88 deletions(-) delete mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml create mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml delete mode 100644 maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c4adc6..ad671e6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,3 +9,6 @@ jobs: name: build-sonar-site-upload uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop secrets: inherit + with: + maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress + verify-goal: --activate-profiles gpgsigning verify diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml deleted file mode 100644 index 7c4adc6..0000000 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows-advanced/ci.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: CI Java (Host) - -on: - push: - workflow_dispatch: - -jobs: - build: - name: build-sonar-site-upload - uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop - secrets: inherit diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml new file mode 100644 index 0000000..b26d822 --- /dev/null +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml @@ -0,0 +1,14 @@ +name: CI Java (Host) + +on: + push: + workflow_dispatch: + +jobs: + build: + name: build-sonar-site-upload + uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop + secrets: inherit + with: + maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress + verify-goal: --activate-profiles jacoco,javadoc,gpgsigning verify diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml deleted file mode 100644 index dfd19da..0000000 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/basic-java.yml +++ /dev/null @@ -1,77 +0,0 @@ -name: Java CI - -on: [ push ] - -env: - GITHUBACTOR: ${{secrets.GITHUBACTOR}} - GITHUBTOKEN: ${{secrets.GITHUBTOKEN}} - SONAR_URL: ${{secrets.SONAR_URL}} - SONAR_TOKEN: ${{secrets.SONAR_TOKEN}} - DOCKERHUB_USERNAME: ${{secrets.DOCKERHUB_USERNAME}} - DOCKERHUB_TOKEN: ${{secrets.DOCKERHUB_TOKEN}} - -jobs: - # This job build, test and stage the artefact and the website for the develop branch - maven-build-test-site: - # The tags to select the runner - runs-on: [ self-hosted, Linux ] - steps: - # Environment setup - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - name: Set up JDK - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - cache: 'maven' - - name: Set up Maven - uses: stCarolas/setup-maven@v4.5 - with: - maven-version: 3.8.6 - - name: Extract branch name - shell: bash - run: echo "MY_BRANCH=$(git rev-parse --abbrev-ref HEAD | tr / _)" >> $GITHUB_ENV - # Build and test - - name: Build and Test with Maven - run: > - mvn --batch-mode \ - --update-snapshots \ - --color always \ - --settings docker/ci-settings.xml \ - -P jacoco \ - verify - # Check quality with SonarQube - ### THIS STEP MUST BE ENABLED BY CONFIGURING : SONAR_URL and SONAR_TOKEN secrets. - - name: Quality check with Sonarqube - shell: bash - if: env.SONAR_URL != null && env.SONAR_TOKEN != null - run: > - mvn -DskipTests=true \ - --batch-mode \ - --color always \ - --settings docker/ci-settings.xml \ - -Dsonar.branch.name=$MY_BRANCH \ - -P jacoco,sonar \ - sonar:sonar - # Stage artifact - - run: mkdir staging && cp target/*.jar staging - - name: Stage artifacts - uses: actions/upload-artifact@v3 - with: - name: Package - path: staging - - name: Install SSH Key - uses: webfactory/ssh-agent@v0.7.0 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - # Build and deploy project site - - name: Build and deploy site with Maven - if: ${{github.ref == 'refs/heads/develop'}} - run: > - mvn --batch-mode \ - --color always \ - --settings docker/ci-settings.xml \ - site:site site-deploy \ No newline at end of file From a6fc1875825cc42807fdd6228bdcaf964627d2c2 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Fri, 26 May 2023 00:38:02 +0200 Subject: [PATCH 18/22] fixes IT --- .github/workflows/ci.yml | 4 ++-- .../META-INF/maven/archetype-metadata.xml | 21 ++++++++++++++++++- .../src/test/java/AppTest.java | 8 +++---- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad671e6..789b3ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,5 +10,5 @@ jobs: uses: ebpro/gh-actions-shared-java/.github/workflows/ci-shareable-maven.yml@develop secrets: inherit with: - maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress - verify-goal: --activate-profiles gpgsigning verify + maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress --activate-profiles github,nexus + verify-goal: --activate-profiles github,nexus,gpgsigning verify diff --git a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml index 628d67d..8842f29 100644 --- a/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml +++ b/maven-archetype-withparent/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -11,7 +11,7 @@ - + src/main/java @@ -77,6 +77,25 @@ .mvn + + + .github + + **/* + + + + docker + + **/* + + + + .mvn + + **/* + + \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java index 5f5716c..063c298 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -1,6 +1,5 @@ package $package; -import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -9,7 +8,6 @@ /** * Unit test for simple App. */ -@Slf4j class AppTest { @Test @@ -19,12 +17,14 @@ void addCorrect() { @Test void addCheckException1() { - assertThrows(NumberFormatException.class, () -> new App().add(-3, 2)); + App app = new App(); + assertThrows(NumberFormatException.class, () -> app.add(-3, 2)); } @Test void addCheckException2() { - assertThrows(NumberFormatException.class, () -> new App().add(3, -2)); + App app = new App(); + assertThrows(NumberFormatException.class, () -> app.add(3, -2)); } } From f1c223733ce9c4ad9b65db390c4deff729c6c341 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Mon, 5 Jun 2023 15:02:53 +0200 Subject: [PATCH 19/22] cleans substitution ans adds -X to mvn CI --- .github/workflows/ci.yml | 2 +- .../archetype-resources/.github/workflows/CI-java.yml | 2 +- .../resources/archetype-resources/src/main/java/App.java | 2 +- .../archetype-resources/src/main/java/module-info.java | 2 +- .../archetype-resources/src/main/java/package-info.java | 2 +- .../src/test-integration/java/AppIT.java | 2 +- .../archetype-resources/src/test/java/AppTest.java | 2 +- .../archetype-resources/src/test/java/SampleTest.java | 2 +- pom.xml | 6 ++++-- 9 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 789b3ec..143af04 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,4 +11,4 @@ jobs: secrets: inherit with: maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress --activate-profiles github,nexus - verify-goal: --activate-profiles github,nexus,gpgsigning verify + verify-goal: -X --activate-profiles github,nexus,gpgsigning verify diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml index b26d822..b1b32c5 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/.github/workflows/CI-java.yml @@ -11,4 +11,4 @@ jobs: secrets: inherit with: maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress - verify-goal: --activate-profiles jacoco,javadoc,gpgsigning verify + verify-goal: -X --activate-profiles jacoco,javadoc,gpgsigning verify diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java index 434ac29..dff6fc1 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/App.java @@ -1,4 +1,4 @@ -package $package; +package ${package}; import lombok.extern.slf4j.Slf4j; diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java index daead9a..8519f22 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/module-info.java @@ -1,7 +1,7 @@ /** * A simple jigsaw module */ -module $package.$artifactId { +module ${package}.${artifactId} { requires org.slf4j; requires ch.qos.logback.classic; requires static lombok; diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java index 08483c9..db6ac28 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/main/java/package-info.java @@ -1,4 +1,4 @@ /** * A simple package documentation */ -package $package; \ No newline at end of file +package ${package}; \ No newline at end of file diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java index 6cac6d2..124a3ba 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test-integration/java/AppIT.java @@ -1,4 +1,4 @@ -package $package; +package ${package}; import static org.junit.jupiter.api.Assertions.*; diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java index 063c298..b3ff5cc 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -1,4 +1,4 @@ -package $package; +package ${package}; import org.junit.jupiter.api.Test; diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java index 57efb1b..ce1e887 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/src/test/java/SampleTest.java @@ -1,4 +1,4 @@ -package $package; +package ${package}; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.*; diff --git a/pom.xml b/pom.xml index b34903d..c85e2ad 100644 --- a/pom.xml +++ b/pom.xml @@ -56,12 +56,14 @@ github GitHub Packages - https://maven.pkg.github.com/${github.account}/${project.artifactId} + + https://maven.pkg.github.com/ebpro/maven-archetypes github GitHub Packages - https://maven.pkg.github.com/${github.account}/${project.artifactId} + + https://maven.pkg.github.com/ebpro/maven-archetypes From ecce52aaacd6f65ad04b7774fe9aea145c83e5dc Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Wed, 7 Jun 2023 11:40:46 +0200 Subject: [PATCH 20/22] cleans build parameters --- .github/workflows/ci.yml | 2 +- ci-settings.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 143af04..789b3ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,4 +11,4 @@ jobs: secrets: inherit with: maven-args: --errors --batch-mode --show-version --update-snapshots --settings ci-settings.xml --color always --no-transfer-progress --activate-profiles github,nexus - verify-goal: -X --activate-profiles github,nexus,gpgsigning verify + verify-goal: --activate-profiles github,nexus,gpgsigning verify diff --git a/ci-settings.xml b/ci-settings.xml index c3ae79e..e487152 100644 --- a/ci-settings.xml +++ b/ci-settings.xml @@ -98,9 +98,9 @@ - + \ No newline at end of file From 12aae00e5a90048b47b9db6eb8f04f277b663716 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Mon, 11 Sep 2023 21:37:23 +0200 Subject: [PATCH 21/22] sets parent release. --- .../src/main/resources/archetype-resources/pom.xml | 2 +- pom.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml index 6f9e757..6d33944 100644 --- a/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml +++ b/maven-archetype-withparent/src/main/resources/archetype-resources/pom.xml @@ -7,7 +7,7 @@ fr.ebruno.maven.poms maven-parentpom - 0.1.0-SNAPSHOT + 0.1.2 ${groupId} diff --git a/pom.xml b/pom.xml index c85e2ad..45d37af 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ fr.ebruno.maven.poms maven-parentpom - 0.1.0-SNAPSHOT + 0.1.2 fr.ebruno.maven.archetypes @@ -127,7 +127,7 @@ org.codehaus.groovy groovy-xml - 3.0.17 + 3.0.19 From dcca5a0dcce93f910665276a90e59ef101e61df8 Mon Sep 17 00:00:00 2001 From: Emmanuel Bruno Date: Mon, 11 Sep 2023 21:37:33 +0200 Subject: [PATCH 22/22] Update versions for release --- maven-archetype-simple/pom.xml | 2 +- maven-archetype-withparent/pom.xml | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/maven-archetype-simple/pom.xml b/maven-archetype-simple/pom.xml index 7b76fdf..8b026a3 100644 --- a/maven-archetype-simple/pom.xml +++ b/maven-archetype-simple/pom.xml @@ -7,7 +7,7 @@ fr.ebruno.maven.archetypes maven-archetypes - 0.1.0-SNAPSHOT + 0.1.0 maven-archetype-simple diff --git a/maven-archetype-withparent/pom.xml b/maven-archetype-withparent/pom.xml index ece7a73..e99546e 100644 --- a/maven-archetype-withparent/pom.xml +++ b/maven-archetype-withparent/pom.xml @@ -8,7 +8,7 @@ fr.ebruno.maven.archetypes maven-archetypes - 0.1.0-SNAPSHOT + 0.1.0 maven-archetype-withparent diff --git a/pom.xml b/pom.xml index 45d37af..42d58e4 100644 --- a/pom.xml +++ b/pom.xml @@ -13,7 +13,7 @@ fr.ebruno.maven.archetypes maven-archetypes - 0.1.0-SNAPSHOT + 0.1.0 pom Apache Maven archetypes