fwcd / kotlin-debug-adapter

Kotlin/JVM debugging for any editor/IDE using the Debug Adapter Protocol
MIT License
120 stars 24 forks source link

* Add a classpath root for Spring Boot searching for application.properties and templates. #44

Closed MrRogerHuang closed 4 years ago

MrRogerHuang commented 4 years ago

Spring Boot searches application.properties and templates by 4 kinds of paths:

  1. A /config subdirectory of the current directory
  2. The current directory
  3. A classpath /config package
  4. The classpath root

See: https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config-application-property-files After run ./gradlew build, application.properties is copied from src/main/resources/application.properties to build/resources/main. Thus, I use the 4th method to let Spring Boot loads application.properties. Path build/resources/main is added as a classpath to kotlin-debug-adapter.

The modified kotlin-debug-adapter works well with debugging this Spring Boot example by "launch": https://github.com/MrMYHuang/SpringBootExample/commit/146f864c755f8766df43f1a44141ee0853d9f194 It might also fix the issue #37.

MrRogerHuang commented 4 years ago

Additionally, this is how to run the example https://github.com/MrMYHuang/SpringBootExample/commit/146f864c755f8766df43f1a44141ee0853d9f194:

  1. ./gradlew build
  2. code .
  3. In vscode, run Debug/Kotlin Launch with this modified kotlin-debug-adapter.
  4. Open http://localhost:8080/greeting and see is there a correct rendered Thymeleaf page.
  5. Open http://localhost:8080/greeting2 and see is there a correct rendered JSP page.
YEXINGZHE54 commented 4 years ago

@MrRogerHuang great job! I encountered this problem too!

MrRogerHuang commented 4 years ago

I developed a Gradle plugin, which can acquire a Gradle project information including classpaths: https://github.com/MrRogerHuang/GradleProjectInfoPlugin It also correctly acquires classpaths if a Gradle project modifies the Java plugin default source sets properties: https://docs.gradle.org/current/userguide/java_plugin.html#sec:source_set_properties For example, if a Gradle project build.gradle has this

sourceSets {
    main.output.resourcesDir = 'xyz'
}

The build resource path will be xyz instead of the default build/resource/main! My plugin can correctly acquire the nondefault resource path.

My plugin might be able to replace the code https://github.com/fwcd/kotlin-debug-adapter/blob/c987ae2c3ce5e6e50103ec5f05bc7de62525ec30/adapter/src/main/kotlin/org/javacs/ktda/classpath/ProjectClassesResolver.kt#L10 and the code https://github.com/fwcd/kotlin-language-server/blob/master/shared/src/main/kotlin/org/javacs/kt/classpath/GradleClassPathResolver.kt

Hope someone can integrate it to kotlin-debug-adapter and kotlin-language-server.