Skip to content

Commit d9e00de

Browse files
authored
Merge pull request #109 from domaframework/fix/sourcepath
Fix sourcepath configuration to preserve existing values
2 parents 069712a + a43a402 commit d9e00de

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

compile/src/main/groovy/org/seasar/doma/gradle/compile/KotlinCompileConfigurator.groovy

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,35 @@ import org.gradle.api.tasks.SourceSet
77
* Configures Kotlin/KAPT compilation tasks for Doma annotation processing.
88
*/
99
class KotlinCompileConfigurator {
10-
10+
1111
private static final String KOTLIN_KAPT_PLUGIN_ID = 'kotlin-kapt'
1212
private static final String KAPT_EXTENSION_NAME = 'kapt'
1313
private static final String SOURCE_PATH_OPTION = '--source-path'
1414
private static final String PARAMETERS_OPTION = '-parameters'
15-
15+
1616
private final Project project
17-
17+
1818
KotlinCompileConfigurator(Project project) {
1919
this.project = Objects.requireNonNull(project)
2020
}
21-
21+
2222
void configure(SourceSet sourceSet) {
2323
project.plugins.withId(KOTLIN_KAPT_PLUGIN_ID) {
2424
configureKapt(sourceSet)
2525
}
2626
}
27-
27+
2828
private void configureKapt(SourceSet sourceSet) {
2929
def kapt = project.extensions.getByName(KAPT_EXTENSION_NAME)
3030
def resourceDirs = sourceSet.resources.srcDirs
31-
def sourcePath = resourceDirs.join(File.pathSeparator)
31+
def newSourcepath = resourceDirs.join(File.pathSeparator)
32+
def currentSourcepath = kapt.javacOptions[SOURCE_PATH_OPTION]
33+
def sourcepath = currentSourcepath == null
34+
? newSourcepath
35+
: currentSourcepath + File.pathSeparator + newSourcepath
3236

3337
kapt.javacOptions {
34-
option SOURCE_PATH_OPTION, sourcePath
38+
option SOURCE_PATH_OPTION, sourcepath
3539
option PARAMETERS_OPTION, ''
3640
}
3741
}

compile/src/main/java/org/seasar/doma/gradle/compile/JavaCompileConfigurator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ private void configureJavaCompile(SourceSet sourceSet, JavaCompile javaCompile)
2929
__ -> {
3030
var resourceDirs = sourceSet.getResources().getSrcDirs();
3131
var options = javaCompile.getOptions();
32-
options.setSourcepath(project.files(resourceDirs));
32+
var newSourcepath = project.files(resourceDirs);
33+
var currentSourcepath = options.getSourcepath();
34+
var sourcepath =
35+
currentSourcepath == null ? newSourcepath : currentSourcepath.plus(newSourcepath);
36+
options.setSourcepath(sourcepath);
3337
options.getCompilerArgs().add(PARAMETERS_COMPILER_ARG);
3438
});
3539
}

0 commit comments

Comments
 (0)