From 44c3862d8d1473b8d4f5420e7ecfaff8c3ab46fd Mon Sep 17 00:00:00 2001
From: Abhishek <abhishekj@spotify.com>
Date: Fri, 14 Mar 2025 16:54:20 +0100
Subject: [PATCH] feat: Generate javadocs and publish on GH Pages

---
 .github/workflows/gen-java-docs.yml | 35 +++++++++++++++++++++++++++++
 pom.xml                             | 20 +++++++++++++++++
 2 files changed, 55 insertions(+)
 create mode 100644 .github/workflows/gen-java-docs.yml

diff --git a/.github/workflows/gen-java-docs.yml b/.github/workflows/gen-java-docs.yml
new file mode 100644
index 00000000..f15e03cc
--- /dev/null
+++ b/.github/workflows/gen-java-docs.yml
@@ -0,0 +1,35 @@
+name: Generate Java Docs
+
+on:
+  push:
+    branches:
+      - master
+
+jobs:
+  build:
+    runs-on: ubuntu-latest
+
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v2
+
+      - name: Set up JDK 11
+        uses: actions/setup-java@v4
+        with:
+          java-version: 11
+          distribution: corretto
+
+      - name: Build with Maven
+        run: mvn clean install
+
+      - name: Generate Javadocs
+        run: mvn javadoc:javadoc
+
+      # Publishes Javadocs to GitHub Pages by pushing to `gh-pages` branch
+      - name: Deploy Javadocs to GitHub Pages
+        run: |
+          git config --global user.name 'github-actions[bot]'
+          git config --global user.email 'github-actions[bot]@users.noreply.github.com'
+          mvn scm-publish:publish-scm
+        env:
+          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 69a41969..e93e0ff2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -393,6 +393,15 @@
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>default-compile</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>compile</goal>
+                        </goals>
+                    </execution>
+                </executions>
                 <configuration>
                     <source>11</source>
                     <target>11</target>
@@ -509,6 +518,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-javadoc-plugin</artifactId>
+                <version>3.3.1</version>
                 <executions>
                     <execution>
                         <id>attach-javadocs</id>
@@ -522,6 +532,16 @@
                     <doclint>none</doclint>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-scm-publish-plugin</artifactId>
+                <version>1.0</version>
+                <configuration>
+                    <content>target/site/apidocs</content>
+                    <pubScmUrl>scm:git:git@github.com:spotify/github-java-client.git</pubScmUrl>
+                    <scmBranch>gh-pages</scmBranch>
+                </configuration>
+            </plugin>
         </plugins>
         <pluginManagement>
             <plugins>