Skip to content

Commit

Permalink
Add an action to run the app
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff5 committed Aug 20, 2024
1 parent d81c83d commit cce10aa
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/build-run-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Build and run sub-project 'app' (GitHub action)
name: build run app

on: [push]

permissions:
contents: read

jobs:
build-run-app-Ubuntu-jdk-17:

runs-on: ubuntu-latest

steps:
- run: echo "Branch ${{ github.ref }} of repository ${{ github.repository }}."
- uses: actions/checkout@v4

- uses: gradle/wrapper-validation-action@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- name: Smoke test with Gradle
run: ./gradlew --no-daemon app:run

- name: Clean up Gradle cache
# Remove some files from the Gradle cache, so they aren't cached
# by GitHub Actions. Restoring these files from a GitHub Actions
# cache might cause problems for future builds.
#https://docs.github.com/en/actions/guides/building-and-testing-java-with-gradle#caching-dependencies
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties
37 changes: 24 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Using Jython 2 in a Modular Project with Gradle

Since v2.7.4, Jython has supported The Java module system,
Since v2.7.4, Jython has supported the Java Platform Module System (JPMS),
and since v2.7.2 (experimentally at first)
it has provided a "slim" JAR as an alternative to the
"standalone" and "classic" JARs.
Expand Down Expand Up @@ -41,28 +41,40 @@ the depended-on classes run with their proper names and integrity.

Jython 2 is unlikely ever fully to embrace
the Java module system for its own use.
(Jython 3 should.)
It can, however, play nicely within a modular project.

[This tutorial on dev.java](https://dev.java/learn/modules) is very helpful
if you are still getting to grips with the detail of modules.

Packages from the slim JAR appear in the automatic module `org.python.jython2`.

*Most* of the dependency JARs also present as modules
*Most* of the dependency JARs also present themselves as modules
(explicit or automatic)
and will be found and resolved by the JVM during start-up.
Some modules are not resolved because
their packages are referenced by name, dynamically.
Even though a JAR may be placed on the module path by the build,
the JVM will not read it if it is not explicitly a dependency.
and will be found and added to the "module graph"
by the JVM during start-up.

Some modules are not added to the graph because
their packages are referenced dynamically.
The declared dependencies are added to the module path by the build,
but surprisingly this does not get them into the module graph.
To make available the full set available we use the option
`--add-modules ALL-MODULE-PATH` on the Java command.

The project shows how to take care of this in the build script.
The project shows how to take care of this in the build script `build.gradle`.
By varying the JVM options there,
you can see module resolution take place (add the `--show-module-resolution` option),
and watch it fail (suppress the `--add-modules`).


## How to Build the Project

Clone this repository onto your own machine.
Open a shell in the root of the project.
I'm using Windows PowerShell here, but the Unix equivalent is easy to work out.

The application is in a sub-project called `app`.
YOu can build it in the root of the project with:
You can build it from the root of the project with:

```
PS demo-jython-slim-gradle> .\gradlew --console=plain app:install
Expand All @@ -76,8 +88,7 @@ PS demo-jython-slim-gradle> .\gradlew --console=plain app:install
BUILD SUCCESSFUL in 11s
4 actionable tasks: 4 executed
```
(I'm using Windows PowerShell here, but the Unix equivalent is easy to work out.
Also, I force Gradle to use a plain console because I find the colours unreadable.)
(I force Gradle to use a plain console because I find the colours unreadable.)

The command has compiled the program,
obtained the Jython slim JAR and all its dependencies,
Expand All @@ -86,7 +97,7 @@ and created a launch script you can run with:
PS demo-jython-slim-gradle> .\app\build\install\app\bin\app
42
```
You can run the application direct;y with Gradle:
You can run the application directly with Gradle:
```
PS demo-jython-slim-gradle> .\gradlew --console=plain app:run
...
Expand All @@ -100,7 +111,7 @@ You can also ask for the contents as a zip or tar file.
The install directory has two subdirectories.
`bin` as we've seen contains the launch cript.
`lib` contains the application JAR, the Jython JAR,
and everything they depend on (that the JDK doesn't supply).
and everything they depend on that the JDK doesn't supply.



0 comments on commit cce10aa

Please sign in to comment.