LoginSignup
3
4

More than 5 years have passed since last update.

7日間苦しんだGradleでコンパイルするとDOMA4019エラーになる原因

Posted at

単純なソースなのにコンパイルできなくてイライラしてたが、結果なんてことのないエラーだった。
二度と起こさないように備忘録。

EclipseのDomaのプラグインで作ったら、ファイルを移さないとエラーになる。

 エラー内容
エラー: [DOMA4019] The file "META-INF/doma/sample/dao/TestDao/selectAll.sql" is not found in the classpath. The absolute path is "/Users/harutotanabe/Downloads/sample/build/classes/java/main/META-INF/doma/sample/dao/TestDao/selectAll.sql".

▼ サンプルコード

Main処理
@SpringBootApplication
public class SampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }

    @Autowired
    TestDao TestDao;

    @Bean
    CommandLineRunner runner() {
        TestDao.selectAll();
        return null;
       }
 }
Entity
@Entity
public class Test {
    public Integer id;
    public String test;
}
Dao
@ConfigAutowireable
@Dao
public interface TestDao {

@select 
List<Test> selectAll();
}
gradle
plugins {
    id 'org.springframework.boot' version '2.1.4.RELEASE'
    id 'java'
}

task copyDomaResources(type: Sync)  {
    from sourceSets.main.resources.srcDirs
    println 'SQLファイルのコピー元'
    println sourceSets.main.resources.srcDirs
    into compileJava.destinationDir
    println 'SQLファイルのコピー先'
    println compileJava.destinationDir
    include 'doma.compile.config'
    include 'META-INF/**/*.sql'
    include 'META-INF/**/*.script'
}

compileJava {
    dependsOn copyDomaResources
    options.encoding = 'UTF-8'
}


apply plugin: 'io.spring.dependency-management'

group = 'doma'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
    mavenLocal()
    maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    compileOnly 'org.projectlombok:lombok'
    compile group: 'org.seasar.doma.boot', name: 'doma-spring-boot-starter', version: '1.1.1'
    runtimeOnly 'org.postgresql:postgresql'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    annotationProcessor "org.seasar.doma:doma:2.24.0"
    implementation "org.seasar.doma:doma:2.24.0"
}

・EclipseのDomaプラグインでエンターだけおしてSQLファイルを作成するとJava配下にできてしまう。

▼ 対応前(イメージ)
image.png

これだとSQLファイルをコピーできない。コピー元がresourcesだから。。。
よって、META-INFフォルダをresourcesに移せばOK

▼ 対応後(イメージ)
image.png

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4