Skip to content

build.gradle: add support for Groovy and Kotlin #1962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wfouche opened this issue Mar 20, 2025 · 6 comments · Fixed by #1965
Closed

build.gradle: add support for Groovy and Kotlin #1962

wfouche opened this issue Mar 20, 2025 · 6 comments · Fixed by #1965
Labels
bug Something isn't working enhancement New feature or request

Comments

@wfouche
Copy link
Contributor

wfouche commented Mar 20, 2025

Describe the bug
jbang export gradle App.kt fails to create a build.gradle file that can build and run the JBang Kotlin app.

JBang version
0.125.0

@wfouche wfouche added the bug Something isn't working label Mar 20, 2025
@wfouche
Copy link
Contributor Author

wfouche commented Mar 20, 2025

Lack of Kotlin support is maybe not a bug as it is most likely that only Java was initially targeted. Kotlin support should be changed to a feature request.

@maxandersen maxandersen added the enhancement New feature or request label Mar 20, 2025
@wfouche
Copy link
Contributor Author

wfouche commented Mar 21, 2025

Changes required to the build.gradle file for a Kotlin project:

(1) Replace java plugin with kotlin.jvm plugin

plugins {
        id 'org.jetbrains.kotlin.jvm' version '2.0.21'
        id 'application'
}

(2) Append Kt to mainClass value, i.e. package-name.App becomes package-name.AppKt

(3) Put source files in src/main/kotlin and not src/main/java folder

(4) An empty settings.gradle file is also required to prevent conflict with top-level settings.gradle file

Applied these changes manually, and I could run the Kotlin app with Gradle.

@wfouche
Copy link
Contributor Author

wfouche commented Mar 21, 2025

Minimal code changes were needed to add Kotlin support. Testing the functionality and will submit a pull request later.

Tested both a working Java project (to ensure that we do not break Java support) and a working Kotlin project.

@quintesse
Copy link
Contributor

This problem is mentioned in #1944, perhaps we should make this issue a sub-issue of it.

@wfouche wfouche changed the title build.gradle: Kotlin support is broken build.gradle: Groovy and Kotlin support is broken Mar 23, 2025
@wfouche wfouche changed the title build.gradle: Groovy and Kotlin support is broken build.gradle: Groovy and Kotlin is not supported Mar 23, 2025
@wfouche
Copy link
Contributor Author

wfouche commented Mar 23, 2025

Groovy supported as well.

@wfouche wfouche changed the title build.gradle: Groovy and Kotlin is not supported build.gradle: add support for Groovy and Kotlin Mar 23, 2025
@wfouche
Copy link
Contributor Author

wfouche commented Mar 23, 2025

Jbang export gradle support tested with Jbang-enabled Java, Groovy and Kotlin apps generated by the Tulip cli.

$ source test_gradle_export.sh

File - test_gradle_export.sh

# Activate Java 11 JDK
sdk env

# Build and install jbang
unset JBANG_JAVA_OPTIONS
./gradlew installDist

export JBANG="`pwd`/build/install/jbang/bin/jbang"
echo $JANG

mkdir temp
pushd temp

echo "Java"
sleep 5

mkdir Java
pushd Java
jbang run tulip-cli@wfouche init Java
$JBANG export gradle io/tulip/App.java
cp benchmark_config.json App
cd App
gradle run
popd

echo "Groovy"
sleep 5

mkdir Groovy
pushd Groovy
jbang run tulip-cli@wfouche init Groovy
$JBANG export gradle io/tulip/App.groovy
cp benchmark_config.json App
cd App
gradle run
popd

echo "Kotlin"
sleep 5

mkdir Kotlin
pushd Kotlin
jbang run tulip-cli@wfouche init Kotlin
$JBANG export gradle io/tulip/App.kt
cp benchmark_config.json App
cd App
gradle run
popd

popd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants