document.write("");

gralde生成Q类 idea

1. 生成Q类:

  IDEA ->File-> Settings-> Build, Execution, Deployment->Compiler->Annotation Processors

  选择右侧的Enable annotation processing(右侧第一行)

  选择Module content root(右侧第4行)

  点击Apply

  点击OK

2. 如果不生效,则copy如下部分到build.gradle中,然后鼠标移到 runAPT 方法的内部,右键,Run 'projectName[runAPT]'

生成Q类后,在generaed文件夹上,右键Mark Directory as -> Generated Sources Root 即可

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
ext {
    querydslGeneratedSourcesDir = file("$projectDir/src/main/generated")
}
//单独运行QueryDSL的APT来生成Q源代码
task runAPT(type: JavaCompile) {
    doFirst {
        /*
         * This is a workaround to delete the file that will be created by the annotation processor if it already exists.
         * There is a known bug in the Java compiler and JDK 8 which should be fixed at JDK 9.
         * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8067747 <-- Master report
         * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8146348 <-- duplicates master report
         */
        if ( querydslGeneratedSourcesDir.exists() ) {
            FileCollection collection = files { querydslGeneratedSourcesDir.listFiles() }
            collection.each { delete it }
        }
        querydslGeneratedSourcesDir.mkdirs()
 
        println "classpath:"+classpath.getFiles()
        println "Generate QueryDsl CLass..."
        println "options:"+options
        println "options.compilerArgs:"+options.compilerArgs
 
        println "AnnotationProcessorPath for $name is ${options.getAnnotationProcessorPath().getFiles()}"
    }
 
    source = sourceSets.main.java.srcDirs
    destinationDir = sourceSets.main.java.outputDir
 
    classpath = configurations.compileClasspath + configurations.annotationProcessor
    options.annotationProcessorPath = classpath  //@wjw_note: 设置这个annotationProcessorPath很关键
 
    options.encoding = 'UTF-8'
    options.deprecation = true
    options.compilerArgs += ["-parameters","-Xlint:deprecation"]
 
    options.compilerArgs += ['-proc:only']
    options.compilerArgs += ['-processor', 'com.querydsl.apt.jpa.JPAAnnotationProcessor']
    options.compilerArgs += ['-s', querydslGeneratedSourcesDir]  //设定生成的Q类存放的位置
    options.compilerArgs += ["-Aquerydsl.excludedPackages=xyz.erupt.upms,xyz.erupt.bi"//设定QueryDsl要排除的包列表(逗号来分割)
}

  

其中runAPT来自: https://blog.csdn.net/wjw465150/article/details/126669946

 

posted @   人间春风意  阅读(213)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示

距今时间:
1025天8.00 小时 37.42 分钟

当前新增阅读数:140327