kotlin
kotlin copied to clipboard
Can't find DangerFileScript in Kotlin Scripting
Hello people, I am trying to activate the autocomplete, and after adding Script template classes and Script templates classpath
I want to activate DangerFileScript but don't see it in Kotlin Scripting.
I see this cause of errors (Unresolved reference: danger) in my Dangerfile.df.kts
`import systems.danger.kotlin.*
danger(args) {
onGitHub {
// Big PR Check
if ((pullRequest.additions ?: 0) - (pullRequest.deletions ?: 0) > 300) {
warn("Big PR, try to keep changes smaller if you can")
}
// Work in progress check
if (pullRequest.title.contains("WIP", false)) {
warn("PR is classed as Work in Progress")
}
}
}`
Am I missing something or doing something wrong? Thank you very much.
I have the same issue
Same issue, you can see what is wrong from the IDE logs
Caused by: kotlin.script.experimental.jvm.util.ClasspathExtractionException: Unable to get script compilation classpath from context, please specify explicit classpath via "kotlin.script.classpath" property
at kotlin.script.experimental.jvm.util.JvmClasspathUtilKt.scriptCompilationClasspathFromContext(jvmClasspathUtil.kt:345)
at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader(jvmScriptCompilation.kt:57)
at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassloader$default(jvmScriptCompilation.kt:50)
at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassContext(jvmScriptCompilation.kt:39)
at kotlin.script.experimental.jvm.JvmScriptCompilationKt.dependenciesFromClassContext$default(jvmScriptCompilation.kt:36)
at systems.danger.kts.DangerFileScriptDefinition$1$1.invoke(DangerFileScriptDefinition.kt:37)
at systems.danger.kts.DangerFileScriptDefinition$1$1.invoke(DangerFileScriptDefinition.kt:36)
at kotlin.script.experimental.util.PropertiesCollection$Builder.invoke(propertiesCollection.kt:282)
at systems.danger.kts.DangerFileScriptDefinition$1.invoke(DangerFileScriptDefinition.kt:36)
at systems.danger.kts.DangerFileScriptDefinition$1.invoke(DangerFileScriptDefinition.kt:34)
at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:23)
at kotlin.script.experimental.api.ScriptCompilationConfiguration.<init>(scriptCompilation.kt:25)
at systems.danger.kts.DangerFileScriptDefinition.<init>(DangerFileScriptDefinition.kt:33)
at systems.danger.kts.DangerFileScriptDefinition.<clinit>(DangerFileScriptDefinition.kt)
Hi, I had the same issue. Here is how I fixed that:
- Do all the instructions from the main README file.
- Go to
Main Menu
->Help
->Edit Custom Properties...
- Add the following line to the file (for macOs the path would probably be different but unfortunately I don't have macOs to provide an example. Probably, something like this
/opt/homebrew/Cellar/danger-kotlin/1.3.0/lib/danger/libs
based on the screenshot in the issue description):kotlin.script.classpath=/usr/local/lib/danger/libs
- Restart your IDE
After that, you should see the DangerFileScript in Kotlin scripting
menu.
Hope it will help someone. Also, the instructions in the main README should probably be updated. I think many people have the same issue and might not use this project because of that
Hi, I had the same issue. Here is how I fixed that:
- Do all the instructions from the main README file.
- Go to
Main Menu
->Help
->Edit Custom Properties...
- Add the following line to the file (for macOs the path would probably be different but unfortunately I don't have macOs to provide an example. Probably, something like this
/opt/homebrew/Cellar/danger-kotlin/1.3.0/lib/danger/libs
based on the screenshot in the issue description):kotlin.script.classpath=/usr/local/lib/danger/libs
- Restart your IDE
After that, you should see the DangerFileScript in
Kotlin scripting
menu.Hope it will help someone. Also, the instructions in the main README should probably be updated. I think many people have the same issue and might not use this project because of that
it didn't help, I suspect because I can't follow the first part of the instructions in the readme, since even the main menu of the new versions of Android Studio doesn't have the appropriate fields
Hi, @ron-diesel. What do you see in kotlin section?
Hi, @ron-diesel. What do you see in kotlin section?
Hi
Please, take a look at issue description. The screenshot from there should help you
Please, take a look at issue description. The screenshot from there should help you
So i need to add such setting as issue author?
Yes, as far as I remember, I did the same. Can share with you my settings once I have access to my laptop
But of course, the path will depend on your system
IDE does not allow to apply this setting. Which version of AS do you use?
Originally, I did it in IntelliJ IDEA. But I just tried it in AS Koala and everything worked (after the AS restart). I did not have any problems with applying those settings.
Android Studio details
Android Studio Koala Feature Drop | 2024.1.2 Build #AI-241.18034.62.2412.12266719, built on August 23, 2024
Originally, I did it in IntelliJ IDEA. But I just tried it in AS Koala and everything worked (after the AS restart). I did not have any problems with applying those settings.
Android Studio details Android Studio Koala Feature Drop | 2024.1.2 Build #AI-241.18034.62.2412.12266719, built on August 23, 2024
Then please tell me where your path leads and what's in the libs folder. In my case there is no libs folder, there is only /opt/homebrew/opt/danger-kotlin/lib/danger/danger-kotlin.jar
I figured it out, it seems the problem is this
is there any workaround for this issue?
@pablobaldez I created an empty Kotlin project, added this
dependencies {
implementation "org.jetbrains.kotlin:kotlin-script-runtime:1.8.22"
implementation files('/opt/homebrew/opt/danger-kotlin/lib/danger/danger-kotlin.jar')
}
to build.gradle, put the danger file into the src/main/kotlin
and edited it with syntax highlighting, then manually transferred the finished script to the main project. There is also an option to wait until this is fixed in Android Studio
Hi, @pablobaldez. Maybe you can try IntelliJ IDEA instead of Android Studio (if you are okay with switching between IDEs of course). I did not observe any issues with IDEA
@OptimumCode I tried the community IntelliJ but then another problem appeared.
I made the DangerFileScript
appears in the Kotlin Scritp list (only after changing idea.properties
file)
But the references still not found in the script file.
obs:
- Restarting the IDE didn't work
- I'm using mac ARM
- This is my idea.properties
kotlin.script.classpath=/opt/homebrew/opt/danger-kotlin/lib/danger
@pablobaldez Unfortunately, I am using Linux not a Mac so I cannot even try to reproduce the problem. However, you probably can find some useful information about the problem's cause in IDE logs. If you are using ToolBox you can click Show log files
and look for idea.log
file. Otherwise, you need to go to Menu > Help > Show logs
in IDE itself (more here)