Skip to content

Commit d3b9b35

Browse files
committed
Fix compiler plugin path not working when library is used as a jar.
1 parent ff21c50 commit d3b9b35

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Configure compilation
4747
sources = listOf(kotlinSource, javaSource)
4848

4949
// pass your own instance of an annotation processor
50-
annotationProcessors = listOf(MyAnnotationProcessor()))
50+
annotationProcessors = listOf(MyAnnotationProcessor())
5151

5252
inheritClasspath = true
5353
messageOutputStream = System.out // see diagnostics in real time
@@ -98,7 +98,7 @@ Add dependency to your module `build.gradle` file:
9898
```Groovy
9999
dependencies {
100100
// ...
101-
implementation 'com.github.tschuchortdev:kotlin-compile-testing:1.1.0'
101+
implementation 'com.github.tschuchortdev:kotlin-compile-testing:1.1.2'
102102
}
103103
```
104104

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
buildscript {
2-
ext.kotlin_version = '1.3.21'
2+
ext.kotlin_version = '1.3.31'
33

44
repositories {
55
mavenCentral()
@@ -22,7 +22,7 @@ apply plugin: 'idea'
2222
apply plugin: 'maven'
2323

2424
group 'com.tschuchort'
25-
version '1.1.0'
25+
version '1.1.2'
2626

2727
sourceCompatibility = 1.8
2828

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip

src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.config.JvmTarget
3333
import org.jetbrains.kotlin.config.Services
3434
import java.io.*
3535
import java.lang.RuntimeException
36+
import java.net.URI
3637
import java.net.URLClassLoader
3738
import java.nio.file.Files
3839
import java.nio.file.Path
@@ -462,10 +463,21 @@ class KotlinCompilation {
462463
}
463464
}
464465

465-
val resourcesPath = this::class.java.classLoader
466-
.getResource("META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar").path
467-
.removeSuffix("META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar")
468-
466+
val resourcesUri = URI.create(
467+
this::class.java.classLoader
468+
.getResource("META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar")
469+
.toString().removeSuffix("/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar")
470+
)
471+
472+
val resourcesPath = when(resourcesUri.scheme) {
473+
"jar" -> resourcesUri.schemeSpecificPart.removeSurrounding("file:", "!")
474+
"file" -> resourcesUri.schemeSpecificPart
475+
else -> throw IllegalStateException(
476+
"Don't know how to handle protocol of ComponentRegistrar plugin. " +
477+
"Did you include this library in a weird way? Only jar and file path are supported."
478+
)
479+
}.removePrefix("/")
480+
469481
val k2JvmArgs = commonK2JVMArgs().also {
470482
it.freeArgs = sourcePaths
471483

0 commit comments

Comments
 (0)