Skip to content

Commit 945a847

Browse files
committed
Refine build scripts to use JDK8 and fix macOS JDK paths
1 parent e53a0ab commit 945a847

File tree

4 files changed

+117
-181
lines changed

4 files changed

+117
-181
lines changed

BUILDING.md

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
# Building Codename One
22

3-
This document provides reproducible instructions for building Codename One and its Android and iOS ports with Maven.
3+
This guide explains how to build Codename One and its Android and iOS ports locally using Maven.
44

55
## Prerequisites
66

7-
- **JDK 11** (Codename One also builds with JDK 8, but these instructions use JDK 11).
8-
- **JDK 17** for building the Android port.
9-
- **Apache Maven 3.6+**.
10-
- macOS with Xcode (only for building the iOS port).
7+
- **JDK 8** (Codename One also builds with JDK 11, but these steps use JDK 8)
8+
- **JDK 17** for building the Android port
9+
- **Apache Maven 3.6+**
10+
- macOS with Xcode (required only for the iOS port)
1111

12-
The `setup-workspace.sh` script downloads these dependencies automatically when they are not already installed.
12+
The helper scripts in the `scripts/` directory download these dependencies when they are not already installed.
1313

1414
### Installing JDKs on Linux
1515

1616
Download binaries from [Adoptium](https://adoptium.net):
1717

1818
```bash
19-
# JDK 11 (Linux x64; adjust `_x64_linux_` for your OS and architecture)
20-
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
21-
tar xf temurin11.tar.gz
22-
export JAVA_HOME=$PWD/jdk-11*
19+
# JDK 8 (Linux x64; adjust `_x64_linux_` for your platform)
20+
curl -L -o temurin8.tar.gz https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u442-b06/OpenJDK8U-jdk_x64_linux_hotspot_8u442b06.tar.gz
21+
tar xf temurin8.tar.gz
22+
export JAVA_HOME=$PWD/jdk8u442-b06
2323

24-
# JDK 17 (Linux x64; adjust `_x64_linux_` for your OS and architecture)
24+
# JDK 17 (Linux x64; adjust `_x64_linux_` for your platform)
2525
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
2626
tar xf temurin17.tar.gz
27-
export JAVA_HOME_17=$PWD/jdk-17*
27+
export JAVA_HOME_17=$PWD/jdk-17.0.16+8
2828

2929
export PATH="$JAVA_HOME/bin:$PATH"
3030
```
3131

32-
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`.
33-
3432
## Preparing the workspace
3533

36-
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.
34+
Clone the repository and run the setup script to download JDK 8 and JDK 17, install Maven, build the core modules, and install the Maven archetypes. This step must be performed before building any ports.
3735

3836
```bash
3937
git clone https://github.com/codenameone/CodenameOne
@@ -46,35 +44,31 @@ The script runs `mvn install` in `maven/`, installs `cn1-maven-archetypes`, and
4644

4745
## Building the Android port
4846

49-
Run the Android build script. It sources the environment from `tools/env.sh`, ensuring `JAVA_HOME` points to JDK 11 and `JAVA_HOME_17` points to JDK 17. If the JDKs are missing, the script will run `setup-workspace.sh` to download them:
47+
The Android port uses JDK 17 for compilation while Maven runs with JDK 8. Run the build script:
5048

5149
```bash
5250
./scripts/build-android-port.sh -DskipTests
5351
```
5452

55-
The resulting artifacts are placed in `maven/android/target`.
53+
Artifacts are placed in `maven/android/target`.
5654

5755
## Building the iOS port
5856

59-
The iOS port can only be built on macOS with Xcode installed. The build script sources `tools/env.sh` and ensures `JAVA_HOME` points to JDK 11, running `setup-workspace.sh` if necessary:
57+
The iOS port can only be built on macOS with Xcode installed. Run the iOS script:
6058

6159
```bash
6260
./scripts/build-ios-port.sh -DskipTests
6361
```
6462

65-
The build output is in `maven/ios/target`.
63+
Artifacts are produced in `maven/ios/target`.
6664

6765
## Convenience scripts
6866

69-
The `scripts` directory contains helper scripts:
70-
71-
- `setup-workspace.sh` – installs Maven, downloads JDK 11 and JDK 17, builds the core modules, installs Maven archetypes, provisions the Codename One build client, and writes `tools/env.sh`.
72-
- `build-android-port.sh` – builds the Android port using JDK 11 for Maven and JDK 17 for compilation.
73-
- `build-ios-port.sh` – builds the iOS port on macOS with JDK 11.
74-
75-
These scripts accept additional Maven arguments, which are passed through to the underlying `mvn` commands.
67+
- `setup-workspace.sh` – installs Maven, downloads JDK 8 and JDK 17, builds the core modules, installs Maven archetypes, provisions the Codename One build client, and writes `tools/env.sh`.
68+
- `build-android-port.sh` – builds the Android port using JDK 8 for Maven and JDK 17 for compilation.
69+
- `build-ios-port.sh` – builds the iOS port on macOS with JDK 8.
7670

7771
## Further reading
7872

79-
- Blog post: *Building Codename One from source, Maven edition*https://www.codenameone.com/blog/building-codename-one-from-source-maven-edition.html
80-
- Maven developers guidehttps://shannah.github.io/codenameone-maven-manual/
73+
- Blog post: <https://www.codenameone.com/blog/building-codename-one-from-source-maven-edition.html>
74+
- Maven developers guide: <https://shannah.github.io/codenameone-maven-manual/>

scripts/build-android-port.sh

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,35 @@
1-
#!/bin/bash
2-
# Build Codename One Android port
3-
set -e
4-
5-
DIR="$(cd "$(dirname "$0")" && pwd)/.."
6-
cd "$DIR"
7-
8-
if [ -f "$DIR/tools/env.sh" ]; then
9-
source "$DIR/tools/env.sh"
10-
fi
11-
12-
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
13-
echo "Provisioning workspace..."
1+
#!/usr/bin/env bash
2+
# Build Codename One Android port using JDK 8 for Maven and JDK 17 for compilation
3+
set -euo pipefail
4+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
5+
cd "$ROOT"
6+
7+
if [ -f "$ROOT/tools/env.sh" ]; then
8+
source "$ROOT/tools/env.sh"
9+
else
1410
./scripts/setup-workspace.sh -q -DskipTests
15-
source "$DIR/tools/env.sh"
11+
source "$ROOT/tools/env.sh"
1612
fi
1713

18-
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
19-
echo "Failed to set up JDK 11." >&2
14+
if ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -q '1\.8'; then
15+
echo "JAVA_HOME must point to JDK 8" >&2
2016
exit 1
2117
fi
22-
23-
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
24-
echo "Provisioning JDK 17..."
25-
./scripts/setup-workspace.sh -q -DskipTests
26-
source "$DIR/tools/env.sh"
27-
fi
28-
29-
if [ -z "$JAVA_HOME_17" ] || ! "$JAVA_HOME_17/bin/java" -version 2>&1 | head -n1 | grep -q "17"; then
30-
echo "Failed to set up JDK 17." >&2
18+
if ! "$JAVA_HOME_17/bin/java" -version 2>&1 | grep -q '17\.0'; then
19+
echo "JAVA_HOME_17 must point to JDK 17" >&2
3120
exit 1
3221
fi
3322

3423
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
35-
36-
echo "JAVA_HOME is set to $JAVA_HOME"
3724
"$JAVA_HOME/bin/java" -version
38-
echo "JAVA_HOME_17 is set to $JAVA_HOME_17"
3925
"$JAVA_HOME_17/bin/java" -version
40-
echo "PATH is $PATH"
41-
mvn -version
26+
"$MAVEN_HOME/bin/mvn" -version
4227

4328
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
4429
if [ ! -f "$BUILD_CLIENT" ]; then
45-
if ! mvn -f maven/pom.xml cn1:install-codenameone "$@"; then
46-
if [ -f maven/CodeNameOneBuildClient.jar ]; then
47-
mkdir -p "$(dirname "$BUILD_CLIENT")"
48-
cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT"
49-
else
50-
echo "maven/CodeNameOneBuildClient.jar not found." >&2
51-
fi
30+
if ! "$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml cn1:install-codenameone "$@"; then
31+
[ -f maven/CodeNameOneBuildClient.jar ] && cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT" || true
5232
fi
5333
fi
5434

55-
mvn -f maven/pom.xml -pl android -am clean install "$@"
35+
"$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml -pl android -am clean install "$@"

scripts/build-ios-port.sh

Lines changed: 17 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,35 @@
1-
#!/bin/bash
2-
# Build Codename One iOS port
3-
# Requires macOS with Xcode installed
4-
set -e
5-
1+
#!/usr/bin/env bash
2+
# Build Codename One iOS port (macOS only)
3+
set -euo pipefail
64
if [[ "$(uname)" != "Darwin" ]]; then
7-
echo "The iOS port can only be built on macOS." >&2
5+
echo "The iOS port can only be built on macOS with Xcode installed." >&2
86
exit 1
97
fi
108
if ! command -v xcodebuild >/dev/null; then
119
echo "Xcode command-line tools not found." >&2
1210
exit 1
1311
fi
14-
15-
DIR="$(cd "$(dirname "$0")" && pwd)/.."
16-
cd "$DIR"
17-
18-
if [ -f "$DIR/tools/env.sh" ]; then
19-
source "$DIR/tools/env.sh"
20-
fi
21-
22-
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
23-
echo "Provisioning workspace..."
12+
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
13+
cd "$ROOT"
14+
if [ -f "$ROOT/tools/env.sh" ]; then
15+
source "$ROOT/tools/env.sh"
16+
else
2417
./scripts/setup-workspace.sh -q -DskipTests
25-
source "$DIR/tools/env.sh"
18+
source "$ROOT/tools/env.sh"
2619
fi
27-
28-
if [ -z "$JAVA_HOME" ] || ! "$JAVA_HOME/bin/java" -version 2>&1 | head -n1 | grep -q "11"; then
29-
echo "Failed to set up JDK 11." >&2
20+
if ! "$JAVA_HOME/bin/java" -version 2>&1 | grep -q '1\.8'; then
21+
echo "JAVA_HOME must point to JDK 8" >&2
3022
exit 1
3123
fi
32-
3324
export PATH="$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH"
34-
35-
echo "JAVA_HOME is set to $JAVA_HOME"
36-
if [ -x "$JAVA_HOME/bin/java" ]; then
37-
"$JAVA_HOME/bin/java" -version
38-
else
39-
echo "java executable not found under $JAVA_HOME" >&2
40-
fi
41-
echo "PATH is $PATH"
42-
mvn -version
25+
"$JAVA_HOME/bin/java" -version
26+
"$MAVEN_HOME/bin/mvn" -version
4327

4428
BUILD_CLIENT="$HOME/.codenameone/CodeNameOneBuildClient.jar"
4529
if [ ! -f "$BUILD_CLIENT" ]; then
46-
if ! mvn -f maven/pom.xml cn1:install-codenameone "$@"; then
47-
if [ -f maven/CodeNameOneBuildClient.jar ]; then
48-
mkdir -p "$(dirname "$BUILD_CLIENT")"
49-
cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT"
50-
else
51-
echo "maven/CodeNameOneBuildClient.jar not found." >&2
52-
fi
30+
if ! "$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml cn1:install-codenameone "$@"; then
31+
[ -f maven/CodeNameOneBuildClient.jar ] && cp maven/CodeNameOneBuildClient.jar "$BUILD_CLIENT" || true
5332
fi
5433
fi
5534

56-
mvn -f maven/pom.xml -pl ios -am clean install "$@"
35+
"$MAVEN_HOME/bin/mvn" -q -f maven/pom.xml -pl ios -am clean install "$@"

0 commit comments

Comments
 (0)