diff --git a/compile-java-test/build.gradle.kts b/compile-java-test/build.gradle.kts index 37777c5..5964919 100644 --- a/compile-java-test/build.gradle.kts +++ b/compile-java-test/build.gradle.kts @@ -23,3 +23,10 @@ dependencies { testRuntimeOnly(libs.junit.jupiter.engine) testRuntimeOnly(libs.junit.platform.launcher) } + +sourceSets { + main { + java.srcDir("src/common/java") + resources.srcDir("src/common/resources") + } +} diff --git a/compile-java-test/src/common/java/common/Department.java b/compile-java-test/src/common/java/common/Department.java new file mode 100644 index 0000000..5eefea6 --- /dev/null +++ b/compile-java-test/src/common/java/common/Department.java @@ -0,0 +1,10 @@ +package common; + +import org.seasar.doma.Entity; +import org.seasar.doma.Id; + +@Entity +public class Department { + @Id public Integer id; + public String name; +} diff --git a/compile-java-test/src/common/java/common/DepartmentDao.java b/compile-java-test/src/common/java/common/DepartmentDao.java new file mode 100644 index 0000000..5f9fc5e --- /dev/null +++ b/compile-java-test/src/common/java/common/DepartmentDao.java @@ -0,0 +1,14 @@ +package common; + +import org.seasar.doma.Dao; +import org.seasar.doma.Script; +import org.seasar.doma.Select; + +@Dao +public interface DepartmentDao { + @Select + Department selectById(Integer id); + + @Script + void create(); +} diff --git a/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/create.script b/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/create.script new file mode 100644 index 0000000..4cd0d89 --- /dev/null +++ b/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/create.script @@ -0,0 +1,4 @@ +create table department( + id integer not null primary key, + name varchar(20) not null, +); diff --git a/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql b/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql new file mode 100644 index 0000000..8d6e05d --- /dev/null +++ b/compile-java-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql @@ -0,0 +1 @@ +select * from department where id = /*id*/0 \ No newline at end of file diff --git a/compile-java-test/src/test/java/example/GenerationTest.java b/compile-java-test/src/test/java/example/GenerationTest.java index 14f0f51..bd6d866 100644 --- a/compile-java-test/src/test/java/example/GenerationTest.java +++ b/compile-java-test/src/test/java/example/GenerationTest.java @@ -2,6 +2,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; +import common.DepartmentDaoImpl; +import common._Department; import org.junit.jupiter.api.Test; public class GenerationTest { @@ -10,5 +12,7 @@ public class GenerationTest { public void test() { assertNotNull(_Employee.class); assertNotNull(EmployeeDaoImpl.class); + assertNotNull(_Department.class); + assertNotNull(DepartmentDaoImpl.class); } } diff --git a/compile-kotlin-test/build.gradle.kts b/compile-kotlin-test/build.gradle.kts index e7c11a3..0b3b0e1 100644 --- a/compile-kotlin-test/build.gradle.kts +++ b/compile-kotlin-test/build.gradle.kts @@ -30,3 +30,12 @@ dependencies { testRuntimeOnly(libs.junit.jupiter.engine) testRuntimeOnly(libs.junit.platform.launcher) } + +kotlin { + sourceSets { + main { + kotlin.srcDir("src/common/kotlin") + resources.srcDir("src/common/resources") + } + } +} \ No newline at end of file diff --git a/compile-kotlin-test/src/common/kotlin/common/Department.kt b/compile-kotlin-test/src/common/kotlin/common/Department.kt new file mode 100644 index 0000000..4453737 --- /dev/null +++ b/compile-kotlin-test/src/common/kotlin/common/Department.kt @@ -0,0 +1,11 @@ +package common + +import org.seasar.doma.Entity +import org.seasar.doma.Id + +@Entity +class Department { + @Id + var id: Int? = null + var name: String? = null +} \ No newline at end of file diff --git a/compile-kotlin-test/src/common/kotlin/common/DepartmentDao.kt b/compile-kotlin-test/src/common/kotlin/common/DepartmentDao.kt new file mode 100644 index 0000000..8d1b499 --- /dev/null +++ b/compile-kotlin-test/src/common/kotlin/common/DepartmentDao.kt @@ -0,0 +1,14 @@ +package common + +import org.seasar.doma.Dao +import org.seasar.doma.Script +import org.seasar.doma.Select + +@Dao +interface DepartmentDao { + @Select + fun selectById(id: Int?): Department? + + @Script + fun create() +} \ No newline at end of file diff --git a/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/create.script b/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/create.script new file mode 100644 index 0000000..4cd0d89 --- /dev/null +++ b/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/create.script @@ -0,0 +1,4 @@ +create table department( + id integer not null primary key, + name varchar(20) not null, +); diff --git a/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql b/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql new file mode 100644 index 0000000..8d6e05d --- /dev/null +++ b/compile-kotlin-test/src/common/resources/META-INF/common/DepartmentDao/selectById.sql @@ -0,0 +1 @@ +select * from department where id = /*id*/0 \ No newline at end of file diff --git a/compile-kotlin-test/src/main/kotlin/example/EmployeeDao.kt b/compile-kotlin-test/src/main/kotlin/example/EmployeeDao.kt index c52fcad..e9d2656 100644 --- a/compile-kotlin-test/src/main/kotlin/example/EmployeeDao.kt +++ b/compile-kotlin-test/src/main/kotlin/example/EmployeeDao.kt @@ -1,5 +1,6 @@ package example +import common.Department import org.seasar.doma.Dao import org.seasar.doma.Script import org.seasar.doma.Select @@ -7,7 +8,7 @@ import org.seasar.doma.Select @Dao interface EmployeeDao { @Select - fun selectById(id: Int?): Employee? + fun selectById(id: Int?): Department? @Script fun create() diff --git a/compile/src/main/groovy/org/seasar/doma/gradle/compile/KotlinCompileConfigurator.groovy b/compile/src/main/groovy/org/seasar/doma/gradle/compile/KotlinCompileConfigurator.groovy index b758a87..fa7d3d1 100644 --- a/compile/src/main/groovy/org/seasar/doma/gradle/compile/KotlinCompileConfigurator.groovy +++ b/compile/src/main/groovy/org/seasar/doma/gradle/compile/KotlinCompileConfigurator.groovy @@ -29,7 +29,7 @@ class KotlinCompileConfigurator { def kapt = project.extensions.getByName(KAPT_EXTENSION_NAME) def resourceDirs = sourceSet.resources.srcDirs def sourcePath = resourceDirs.join(File.pathSeparator) - + kapt.javacOptions { option SOURCE_PATH_OPTION, sourcePath option PARAMETERS_OPTION, '' diff --git a/compile/src/main/java/org/seasar/doma/gradle/compile/CompileConfigurator.java b/compile/src/main/java/org/seasar/doma/gradle/compile/CompileConfigurator.java index b8b2436..b6069e0 100644 --- a/compile/src/main/java/org/seasar/doma/gradle/compile/CompileConfigurator.java +++ b/compile/src/main/java/org/seasar/doma/gradle/compile/CompileConfigurator.java @@ -19,14 +19,19 @@ class CompileConfigurator { } void configure() { + // Configure immediately for Java var javaExtension = project.getExtensions().getByType(JavaPluginExtension.class); var mainSourceSet = javaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); + javaConfigurator.configure(mainSourceSet); - configureSourceSet(mainSourceSet); - } - - private void configureSourceSet(SourceSet sourceSet) { - javaConfigurator.configure(sourceSet); - kotlinConfigurator.configure(sourceSet); + // Defer Kotlin configuration until after project evaluation + project.afterEvaluate( + evaluatedProject -> { + var evaluatedJavaExtension = + evaluatedProject.getExtensions().getByType(JavaPluginExtension.class); + var evaluatedMainSourceSet = + evaluatedJavaExtension.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME); + kotlinConfigurator.configure(evaluatedMainSourceSet); + }); } } diff --git a/compile/src/main/java/org/seasar/doma/gradle/compile/JavaCompileConfigurator.java b/compile/src/main/java/org/seasar/doma/gradle/compile/JavaCompileConfigurator.java index 3821617..674d075 100644 --- a/compile/src/main/java/org/seasar/doma/gradle/compile/JavaCompileConfigurator.java +++ b/compile/src/main/java/org/seasar/doma/gradle/compile/JavaCompileConfigurator.java @@ -17,16 +17,20 @@ class JavaCompileConfigurator { } void configure(SourceSet sourceSet) { - var resourceDirs = sourceSet.getResources().getSrcDirs(); var compileTaskName = sourceSet.getCompileJavaTaskName(); - project .getTasks() .named(compileTaskName, JavaCompile.class) - .configure( - javaCompile -> { - javaCompile.getOptions().setSourcepath(project.files(resourceDirs)); - javaCompile.getOptions().getCompilerArgs().add(PARAMETERS_COMPILER_ARG); - }); + .configure(javaCompile -> configureJavaCompile(sourceSet, javaCompile)); + } + + private void configureJavaCompile(SourceSet sourceSet, JavaCompile javaCompile) { + javaCompile.doFirst( + __ -> { + var resourceDirs = sourceSet.getResources().getSrcDirs(); + var options = javaCompile.getOptions(); + options.setSourcepath(project.files(resourceDirs)); + options.getCompilerArgs().add(PARAMETERS_COMPILER_ARG); + }); } }