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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· 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工具