Skip to content

Commit ae23c2f

Browse files
committed
CI: let build scripts provision JDK
1 parent 6ce1275 commit ae23c2f

File tree

6 files changed

+290
-0
lines changed

6 files changed

+290
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Test Android build scripts
3+
4+
'on':
5+
push:
6+
paths:
7+
- 'scripts/**'
8+
pull_request:
9+
paths:
10+
- 'scripts/**'
11+
12+
jobs:
13+
build-android:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Build Android port
18+
run: |
19+
./scripts/setup-workspace.sh -q -DskipTests
20+
./scripts/build-android-port.sh -q -DskipTests

.github/workflows/scripts-ios.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Test iOS build scripts
3+
4+
'on':
5+
push:
6+
paths:
7+
- 'scripts/**'
8+
pull_request:
9+
paths:
10+
- 'scripts/**'
11+
12+
jobs:
13+
build-ios:
14+
runs-on: macos-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Build iOS port
18+
run: |
19+
./scripts/setup-workspace.sh -q -DskipTests
20+
./scripts/build-ios-port.sh -q -DskipTests

BUILDING.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Building Codename One
2+
3+
This guide describes how to build Codename One and its Android and iOS ports locally using Maven. It includes reproducible steps for setting up the workspace and compiling each port.
4+
5+
## Prerequisites
6+
7+
- **JDK 11** for building the main project and the iOS port.
8+
- **JDK 17** for building the Android port.
9+
- **Apache Maven 3.6+**.
10+
11+
The `setup-workspace.sh` script downloads these dependencies automatically when they are not already installed.
12+
13+
### Installing JDKs on Linux
14+
15+
Download binaries from [Adoptium](https://adoptium.net):
16+
17+
```bash
18+
# JDK 11 (Linux x64; adjust `_x64_linux_` for your OS and architecture)
19+
curl -L -o temurin11.tar.gz https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28%2B6/OpenJDK11U-jdk_x64_linux_hotspot_11.0.28_6.tar.gz
20+
tar xf temurin11.tar.gz
21+
export JAVA_HOME=$PWD/jdk-11*
22+
23+
# JDK 17 (Linux x64; adjust `_x64_linux_` for your OS and architecture)
24+
curl -L -o temurin17.tar.gz https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16%2B8/OpenJDK17U-jdk_x64_linux_hotspot_17.0.16_8.tar.gz
25+
tar xf temurin17.tar.gz
26+
export JAVA_HOME_17=$PWD/jdk-17*
27+
28+
export PATH="$JAVA_HOME/bin:$PATH"
29+
```
30+
31+
The Android port uses JDK 17 while Maven runs with JDK 11. The helper scripts download both JDKs and set `JAVA_HOME` and `JAVA_HOME_17`.
32+
33+
## Preparing the workspace
34+
35+
Clone the repository and run the setup script to install Maven, download JDK 11 and JDK 17, build the core modules, and install the Maven archetypes. This step must be performed before building any ports.
36+
37+
```bash
38+
git clone https://github.com/codenameone/CodenameOne
39+
cd CodenameOne
40+
./scripts/setup-workspace.sh -DskipTests
41+
```
42+
43+
The script runs `mvn install` in `maven/`, installs `cn1-maven-archetypes`, and ensures `~/.codenameone/CodeNameOneBuildClient.jar` is installed by invoking the `cn1:install-codenameone` Maven goal. If that goal fails, the script copies the jar from `maven/CodeNameOneBuildClient.jar`.
44+
45+
## Building the Android port
46+
47+
Run the Android build script. It requires `JAVA_HOME` pointing to JDK 11 and `JAVA_HOME_17` pointing to JDK 17. If these variables are unset, the script will look for the JDKs under `tools/` as provisioned by `setup-workspace.sh`:
48+
49+
```bash
50+
./scripts/build-android-port.sh -DskipTests
51+
```
52+
53+
The resulting artifacts are placed in `maven/android/target`.
54+
55+
## Building the iOS port
56+
57+
The iOS port can only be built on macOS with Xcode installed. The build script expects `JAVA_HOME` to point to JDK 11 and will search `tools/` if it is not set:
58+
59+
```bash
60+
./scripts/build-ios-port.sh -DskipTests
61+
```
62+
63+
The build output is in `maven/ios/target`.
64+
65+
## Convenience scripts
66+
67+
The `scripts` directory contains helper scripts:
68+
69+
- `setup-workspace.sh` – installs Maven, downloads JDK 11 and JDK 17, builds the core modules, installs Maven archetypes, and provisions the Codename One build client.
70+
- `build-android-port.sh` – builds the Android port using JDK 11 for Maven and JDK 17 for compilation.
71+
- `build-ios-port.sh` – builds the iOS port on macOS with JDK 11.
72+
73+
These scripts accept additional Maven arguments, which are passed through to the underlying `mvn` commands.
74+
75+
## Further reading
76+
77+
- Blog post: *Building Codename One from source, Maven edition*https://www.codenameone.com/blog/building-codename-one-from-source-maven-edition.html
78+
- Maven developers guide – https://shannah.github.io/codenameone-maven-manual/

scripts/build-android-port.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Build Codename One Android port
3+
set -e
4+
5+
DIR="$(cd "$(dirname "$0")" && pwd)/.."
6+
cd "$DIR"
7+
8+
# Locate JDK 11
9+
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
10+
JAVA_HOME=$(ls -d "$DIR"/tools/jdk-11* 2>/dev/null | head -n1)
11+
fi
12+
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
13+
echo "JAVA_HOME must point to JDK 11." >&2
14+
exit 1
15+
fi
16+
17+
# Locate JDK 17
18+
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
19+
JAVA_HOME_17=$(ls -d "$DIR"/tools/jdk-17* 2>/dev/null | head -n1)
20+
fi
21+
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
22+
echo "JAVA_HOME_17 must point to JDK 17." >&2
23+
exit 1
24+
fi
25+
26+
export PATH="$JAVA_HOME/bin:$PATH"
27+
28+
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
29+
if [ ! -f "$BUILD_CLIENT" ]; then
30+
if ! mvn -f maven/pom.xml cn1:install-codenameone "$@"; then
31+
if [ -f maven/CodeNameOneBuildClient.jar ]; then
32+
mkdir -p "$(dirname "$BUILD_CLIENT")"
33+
cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT"
34+
else
35+
echo "maven/CodeNameOneBuildClient.jar not found." >&2
36+
fi
37+
fi
38+
fi
39+
40+
mvn -f maven/pom.xml -pl android -am clean install "$@"

scripts/build-ios-port.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Build Codename One iOS port
3+
# Requires macOS with Xcode installed
4+
set -e
5+
6+
if [[ "$(uname)" != "Darwin" ]]; then
7+
echo "The iOS port can only be built on macOS." >&2
8+
exit 1
9+
fi
10+
if ! command -v xcodebuild >/dev/null; then
11+
echo "Xcode command-line tools not found." >&2
12+
exit 1
13+
fi
14+
15+
DIR="$(cd "$(dirname "$0")" && pwd)/.."
16+
cd "$DIR"
17+
18+
# Locate JDK 11
19+
if [ -z "$JAVA_HOME" ]; then
20+
JAVA_HOME=$(ls -d "$DIR"/tools/jdk-11* 2>/dev/null | head -n1)
21+
fi
22+
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
23+
echo "JAVA_HOME must point to JDK 11." >&2
24+
exit 1
25+
fi
26+
27+
export PATH="$JAVA_HOME/bin:$PATH"
28+
29+
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
30+
if [ ! -f "$BUILD_CLIENT" ]; then
31+
if ! mvn -f maven/pom.xml cn1:install-codenameone "$@"; then
32+
if [ -f maven/CodeNameOneBuildClient.jar ]; then
33+
mkdir -p "$(dirname "$BUILD_CLIENT")"
34+
cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT"
35+
else
36+
echo "maven/CodeNameOneBuildClient.jar not found." >&2
37+
fi
38+
fi
39+
fi
40+
41+
mvn -f maven/pom.xml -pl ios -am clean install "$@"

scripts/setup-workspace.sh

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#!/bin/bash
2+
# Prepare Codename One workspace by installing Maven, provisioning JDK 11 and JDK 17,
3+
# building core modules, and installing Maven archetypes
4+
set -e
5+
DIR="$(cd "$(dirname "$0")" && pwd)/.."
6+
cd "$DIR"
7+
8+
TOOLS_DIR="$DIR/tools"
9+
mkdir -p "$TOOLS_DIR"
10+
11+
ensure_jdk() {
12+
local envvar="$1" version="$2" url="$3"
13+
local current="${!envvar}"
14+
if [ -z "$current" ] || ! "$current/bin/java" -version 2>&1 | head -n1 | grep -q "$version"; then
15+
local existing=$(ls -d "$TOOLS_DIR"/jdk-$version* 2>/dev/null | head -n1)
16+
if [ -z "$existing" ]; then
17+
echo "Downloading JDK $version (this may take a while)..."
18+
local archive="$TOOLS_DIR/jdk$version.tar.gz"
19+
curl -L -o "$archive" "$url"
20+
tar -xzf "$archive" -C "$TOOLS_DIR"
21+
rm "$archive"
22+
existing=$(ls -d "$TOOLS_DIR"/jdk-$version* | head -n1)
23+
fi
24+
export "$envvar"="$existing"
25+
fi
26+
}
27+
28+
ensure_maven() {
29+
if ! command -v mvn >/dev/null; then
30+
local version="3.9.6"
31+
local archive="$TOOLS_DIR/apache-maven-$version-bin.tar.gz"
32+
echo "Downloading Maven $version..."
33+
curl -L -o "$archive" "https://archive.apache.org/dist/maven/maven-3/$version/binaries/apache-maven-$version-bin.tar.gz"
34+
tar -xzf "$archive" -C "$TOOLS_DIR"
35+
rm "$archive"
36+
MAVEN_HOME="$TOOLS_DIR/apache-maven-$version"
37+
export PATH="$MAVEN_HOME/bin:$PATH"
38+
fi
39+
}
40+
41+
detect_platform() {
42+
case "$(uname -s)" in
43+
Linux) platform="linux" ;;
44+
Darwin) platform="mac" ;;
45+
*) echo "Unsupported OS: $(uname -s)" >&2; exit 1 ;;
46+
esac
47+
48+
case "$(uname -m)" in
49+
x86_64|amd64) arch="x64" ;;
50+
arm64|aarch64) arch="aarch64" ;;
51+
*) echo "Unsupported architecture: $(uname -m)" >&2; exit 1 ;;
52+
esac
53+
}
54+
55+
detect_platform
56+
57+
JDK11_URL="https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.28%2B6/"\
58+
"OpenJDK11U-jdk_${arch}_${platform}_hotspot_11.0.28_6.tar.gz"
59+
JDK17_URL="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.16%2B8/"\
60+
"OpenJDK17U-jdk_${arch}_${platform}_hotspot_17.0.16_8.tar.gz"
61+
62+
ensure_jdk JAVA_HOME 11 "$JDK11_URL"
63+
ensure_jdk JAVA_HOME_17 17 "$JDK17_URL"
64+
65+
ensure_maven
66+
67+
export PATH="$JAVA_HOME/bin:$PATH"
68+
69+
mvn -f maven/pom.xml install "$@"
70+
71+
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
72+
if [ ! -f "$BUILD_CLIENT" ]; then
73+
echo "Installing Codename One build client..."
74+
if ! mvn -f maven/pom.xml cn1:install-codenameone "$@"; then
75+
echo "Falling back to manual copy of build client jar." >&2
76+
if [ -f maven/CodeNameOneBuildClient.jar ]; then
77+
mkdir -p "$(dirname "$BUILD_CLIENT")"
78+
cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT"
79+
else
80+
echo "maven/CodeNameOneBuildClient.jar not found." >&2
81+
fi
82+
fi
83+
fi
84+
85+
if [ ! -d cn1-maven-archetypes ]; then
86+
git clone https://github.com/shannah/cn1-maven-archetypes
87+
fi
88+
(
89+
cd cn1-maven-archetypes
90+
mvn install "$@"
91+
)

0 commit comments

Comments
 (0)