From ed89bfef79b01a2e76d202475eaad83652157674 Mon Sep 17 00:00:00 2001
From: Lukas Malte Monnerjahn <lukasmalte.monnerjahn@dataport.de>
Date: Tue, 18 Jun 2024 17:54:37 +0200
Subject: [PATCH] KOP-2330 KOP-2331 Deployment auf Artifactory und Nexus

---
 .gitignore       |  3 +++
 .gitlab-ci.yml   | 20 +++++++++++++++++++-
 .m2/settings.xml | 10 ++++++++++
 pom.xml          | 41 ++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/.gitignore b/.gitignore
index 99afcfa..333dba2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,9 @@ target/
 .project
 .settings
 .gitlab-ci-local
+.m2/
+!.m2/settings.xml
+.mvn/
 
 # IDE
 .settings/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index e3ec261..cbda740 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@ image: dimage-base-release.repo-ex.zcdi.dataport.de/sdks/maven:3.9.2-java-21
 
 variables:
   MAVEN_CLI_OPTS: "-s .m2/settings.xml --batch-mode"
+  MAVEN_DEPLOY_CLI_OPTS: "--no-transfer-progress"
   MAVEN_OPTS: "-Dmaven.repo.local=.m2/repository"
 
 cache:
@@ -13,9 +14,26 @@ cache:
 package:
   stage: build
   script:
-    - export DATAPORT_PROXY=$DATAPORT_PROXY
+    - export DATAPORT_PROXY_CLI=$DATAPORT_PROXY
     - mvn $MAVEN_CLI_OPTS package
   artifacts:
     paths:
       - target/*.jar
+  rules:
+    - if: $CI_COMMIT_BRANCH != "main"
 
+deploy_to_artifactory:
+  stage: deploy
+  script:
+    - export DATAPORT_PROXY_CLI=$DATAPORT_PROXY
+    - mvn -P artifactory-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS deploy
+  only:
+    - main
+
+deploy_to_nexus:
+  stage: deploy
+  script:
+    - export DATAPORT_PROXY_CLI=$DATAPORT_PROXY
+    - mvn -P nexus-deploy $MAVEN_DEPLOY_CLI_OPTS $MAVEN_CLI_OPTS deploy
+  only:
+    - main
diff --git a/.m2/settings.xml b/.m2/settings.xml
index 7a5f70a..8b317f9 100644
--- a/.m2/settings.xml
+++ b/.m2/settings.xml
@@ -12,6 +12,16 @@
             <username>${env.Artifactory_REPO_USER}</username>
             <password>${env.Artifactory_REPO_PASS}</password>
         </server>
+        <server>
+            <id>ozg-nexus</id>
+            <username>${env.Nexus_REPO_USER}</username>
+            <password>${env.Nexus_REPO_PASS}</password>
+        </server>
+        <server>
+            <id>ozg-snapshots-nexus</id>
+            <username>${env.Nexus_REPO_USER}</username>
+            <password>${env.Nexus_REPO_PASS}</password>
+        </server>
     </servers>
     <profiles>
         <profile>
diff --git a/pom.xml b/pom.xml
index 95f8b3d..4b455ce 100644
--- a/pom.xml
+++ b/pom.xml
@@ -13,5 +13,44 @@
         <maven.compiler.target>21</maven.compiler.target>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
-    
+
+    <profiles>
+        <!-- Deployment Profiles -->
+        <profile>
+            <id>artifactory-deploy</id>
+            <activation>
+                <activeByDefault>false</activeByDefault>
+            </activation>
+            <distributionManagement>
+                <repository>
+                    <id>artifactory</id>
+                    <name>artifactory</name>
+                    <url>${env.DATAPORT_ARTIFACTORY_URL}</url>
+                </repository>
+                <snapshotRepository>
+                    <id>artifactory-snapshots</id>
+                    <name>artifactory-snapshots</name>
+                    <url>${env.DATAPORT_ARTIFACTORY_URL}</url>
+                </snapshotRepository>
+            </distributionManagement>
+        </profile>
+        <profile>
+            <id>nexus-deploy</id>
+            <activation>
+                <activeByDefault>false</activeByDefault>
+            </activation>
+            <distributionManagement>
+                <repository>
+                    <id>ozg-nexus</id>
+                    <name>ozg-releases</name>
+                    <url>https://nexus.ozg-sh.de/repository/ozg-releases/</url>
+                </repository>
+                <snapshotRepository>
+                    <id>ozg-snapshots-nexus</id>
+                    <name>ozg-snapshots</name>
+                    <url>https://nexus.ozg-sh.de/repository/ozg-snapshots/</url>
+                </snapshotRepository>
+            </distributionManagement>
+        </profile>
+    </profiles>
 </project>
\ No newline at end of file
-- 
GitLab