Skip to content
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

--package is broken in 4.2.3 - doesn't include stuff in local dependencies #415

Open
vsajip opened this issue Jan 21, 2024 · 0 comments
Open

Comments

@vsajip
Copy link
Contributor

vsajip commented Jan 21, 2024

I have a simple setup where packaging a script with a local dependency fails, because the local dependency is not included in the package. Here is the project:

$ tree .
.
├── libs
│   └── congocc.jar
└── pkgtest.kts

The script just imports a class in congocc.jar and prints it:

import org.congocc.core.Grammar

println(Grammar::class.java)

which runs fine when invoked like this:

$ KSCRIPT_DIRECTORY_ARTIFACTS=$PWD/libs kscript pkgtest.kts
class org.congocc.core.Grammar

However, packaging it fails:

$ KSCRIPT_DIRECTORY_ARTIFACTS=$PWD/libs kscript -cp pkgtest.kts
Cleaning up cache...
[kscript] Packaging script 'pkgtest' into standalone executable...
[kscript] Packaged script 'pkgtest' available at path:
[ksript] /home/vinay/.cache/kscript/package_9c6421c9540b73cf0ccfbcfd1405be52/build/libs/pkgtest
$ /home/vinay/.cache/kscript/package_9c6421c9540b73cf0ccfbcfd1405be52/build/libs/pkgtest
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at Main_Pkgtest$Companion.main(Main_Pkgtest.kt:6)
	at Main_Pkgtest.main(Main_Pkgtest.kt)
Caused by: java.lang.NoClassDefFoundError: org/congocc/core/Grammar
	at kscript.scriplet.Pkgtest.<init>(Pkgtest.kts)
	... 6 more
Caused by: java.lang.ClassNotFoundException: org.congocc.core.Grammar
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:527)
	... 7 more

This is because the build.gradle.kts is missing the dependency. Here is the relevant portion of build.gradle.kts:

dependencies {
    implementation(files("/home/vinay/.cache/kscript/jar_9c6421c9540b73cf0ccfbcfd1405be52/scriplet.jar"))
    implementation("org.jetbrains.kotlin:kotlin-stdlib")
    implementation("org.jetbrains.kotlin:kotlin-script-runtime:1.7.21")
}

There's no mention of congocc.jar, even though it is contained in the relevant dependencies file:

$ cat ~/.cache/kscript/dependencies_9c6421c9540b73cf0ccfbcfd1405be52/dependencies.content 
/home/vinay/projects/scratch/kscript/libs/congocc.jar

Adding implementation(files("/home/vinay/projects/scratch/kscript/libs/congocc.jar")) manually to the build script and rerunning gradle makeScript solves the problem, so it's just in the construction of build.gradle.kts where the problem seems to be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant