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

Can't find DangerFileScript in Kotlin Scripting #276

Open
gulomov opened this issue Apr 12, 2024 · 20 comments
Open

Can't find DangerFileScript in Kotlin Scripting #276

gulomov opened this issue Apr 12, 2024 · 20 comments

Comments

@gulomov
Copy link

gulomov commented Apr 12, 2024

Hello people, I am trying to activate the autocomplete, and after adding Script template classes and Script templates classpath
Screenshot 2024-04-12 at 13 19 34

I want to activate DangerFileScript but don't see it in Kotlin Scripting.

Screenshot 2024-04-12 at 13 25 00

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.

@carlosesh
Copy link

I have the same issue

@efemoney
Copy link

efemoney commented Jun 7, 2024

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)

@OptimumCode
Copy link

OptimumCode commented Jun 22, 2024

Hi, I had the same issue. Here is how I fixed that:

  1. Do all the instructions from the main README file.
  2. Go to Main Menu -> Help -> Edit Custom Properties...
  3. 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
  4. Restart your IDE

After that, you should see the DangerFileScript in Kotlin scripting menu.
image

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

@ron-diesel
Copy link

Hi, I had the same issue. Here is how I fixed that:

  1. Do all the instructions from the main README file.
  2. Go to Main Menu -> Help -> Edit Custom Properties...
  3. 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
  4. Restart your IDE

After that, you should see the DangerFileScript in Kotlin scripting menu. image

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

@OptimumCode
Copy link

Hi, @ron-diesel. What do you see in kotlin section?

@ron-diesel
Copy link

Hi, @ron-diesel. What do you see in kotlin section?

Hi
image

@ron-diesel
Copy link

image

@OptimumCode
Copy link

Please, take a look at issue description. The screenshot from there should help you

@ron-diesel
Copy link

Please, take a look at issue description. The screenshot from there should help you

So i need to add such setting as issue author?
image

@OptimumCode
Copy link

Yes, as far as I remember, I did the same. Can share with you my settings once I have access to my laptop

@OptimumCode
Copy link

But of course, the path will depend on your system

@ron-diesel
Copy link

IDE does not allow to apply this setting. Which version of AS do you use?

@OptimumCode
Copy link

OptimumCode commented Sep 10, 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

@ron-diesel
Copy link

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

@ron-diesel
Copy link

I figured it out, it seems the problem is this

@pablobaldez
Copy link

is there any workaround for this issue?

@ron-diesel
Copy link

ron-diesel commented Sep 11, 2024

@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

@OptimumCode
Copy link

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

@pablobaldez
Copy link

pablobaldez commented Sep 11, 2024

@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
Screenshot 2024-09-11 at 14 01 24 Screenshot 2024-09-11 at 14 02 58

@OptimumCode
Copy link

@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
image

and look for idea.log file. Otherwise, you need to go to Menu > Help > Show logs in IDE itself (more here)

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

6 participants