Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@ import org.gradle.api.tasks.SourceSet
* Configures Kotlin/KAPT compilation tasks for Doma annotation processing.
*/
class KotlinCompileConfigurator {

private static final String KOTLIN_KAPT_PLUGIN_ID = 'kotlin-kapt'
private static final String KAPT_EXTENSION_NAME = 'kapt'
private static final String SOURCE_PATH_OPTION = '--source-path'
private static final String PARAMETERS_OPTION = '-parameters'

private final Project project

KotlinCompileConfigurator(Project project) {
this.project = Objects.requireNonNull(project)
}

void configure(SourceSet sourceSet) {
project.plugins.withId(KOTLIN_KAPT_PLUGIN_ID) {
configureKapt(sourceSet)
}
}

private void configureKapt(SourceSet sourceSet) {
def kapt = project.extensions.getByName(KAPT_EXTENSION_NAME)
def resourceDirs = sourceSet.resources.srcDirs
def sourcePath = resourceDirs.join(File.pathSeparator)
def newSourcepath = resourceDirs.join(File.pathSeparator)
def currentSourcepath = kapt.javacOptions[SOURCE_PATH_OPTION]
def sourcepath = currentSourcepath == null
? newSourcepath
: currentSourcepath + File.pathSeparator + newSourcepath

kapt.javacOptions {
option SOURCE_PATH_OPTION, sourcePath
option SOURCE_PATH_OPTION, sourcepath
option PARAMETERS_OPTION, ''
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ private void configureJavaCompile(SourceSet sourceSet, JavaCompile javaCompile)
__ -> {
var resourceDirs = sourceSet.getResources().getSrcDirs();
var options = javaCompile.getOptions();
options.setSourcepath(project.files(resourceDirs));
var newSourcepath = project.files(resourceDirs);
var currentSourcepath = options.getSourcepath();
var sourcepath =
currentSourcepath == null ? newSourcepath : currentSourcepath.plus(newSourcepath);
options.setSourcepath(sourcepath);
options.getCompilerArgs().add(PARAMETERS_COMPILER_ARG);
});
}
Expand Down