Get the App
SLTechnology News&Howtos  ›  Development  › 

Why can't the GenerateSources of Idea generate QueryDSL problems?

Shulou Source: shulou.com Published: 2022-06-02 17:57:09 10月28日 Update

This article mainly explains "how Idea GenerateSources cannot generate QueryDSL problems", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "how Idea's GenerateSources cannot generate QueryDSL problems"!

QueryDSL Introduction

official website

QueryDSL is just a generic query framework focused on building type-safe SQL queries through Java APIs.

Querydsl can build query statements suitable for different types of ORM frameworks or SQL through a set of common query APIs, that is to say, QueryDSL is a common query framework based on various ORM frameworks and SQL.

QueryDSL enables queries to be built in a common API manner on any supported ORM framework or SQL platform. QueryDSL currently supports JPA,JDO,SQL,Java Collections,RDF,Lucene,Hibernate Search.

Today is the first day of working from home in 2020, and there is a phenomenon different from that in the company. The deploy project failed when it arrived at the maven library, but it has been successful before.

The reason is that QueryDSL class is not generated, but why in the company but not at home?

Since Idea's "Generate Sources And Update Folders" operation is fleeting, there is too little information, so it is not possible to trace back from the principle first.

1. The first question is: What happens when Idea's "Generate Sources And Update Folders" action is executed?

Refer to stackoverflow and explain as follows

In order to get generated sources automatically imported as source folders configure corresponding pluginsso that they put them into target/generated-sources/, where subdir is any folder name you prefer.The subdir folder is necessary to distinguish sources from different tools and also to exclude some special generated sources (e.g. groovy stubs).Please note that even if you manually configure some source folders under target/generated-sources of this folder itself,IDEA will rewrite them according to your pom.xml.Any time you want to generate sources you simply execute the corresponding goal,bound for generation (usually generate-sources, generate-test-sources). After that IDEA will pick up new folders and set them up.As you can see Generate Sources action runs the generate-sources Maven phase for any plug-ins in your pom.xml that do generate any sources. "Generate Source" is actually executing Maven's generate-sources steps with all plug-ins that can generate sources

What do you need to know about Maven's phase? Generate-sources What is the timing of execution?

The answer is that the generates phase will be executed between the validate and compile phases, see here for details.

2. So the second question comes, which plugins in our project can perform generate sources?

It is easy to find the following configuration (this plugin is open source on github)

com.mysema.maven apt-maven-plugin process target/generated-sources/java com.querydsl.apt.jpa.JPAAnnotationProcessor com.querydsl querydsl-apt 4.1.3

apt-maven-plugin provides Maven integration of the Java 6 APT functionality.

What is Java APT?

APT(Annotation Process Tool) is a method of processing annotations during code compilation. According to certain rules, the corresponding java files are generated. It is mostly used for processing custom annotations.

Dagger2, ButterKnife, EventBus3 are currently more popular APT technology, little impact on runtime performance, that is to say, APT is a tool to generate code with code, java files will be generated in the process, so why do we end up generating only class files? This is because many plugins do a second cleanup.

After Java 8 APT was "Pluggable Annotation Processing API". In addition, this plug-in depends on querydsl, so querydsl is also necessary to understand

QueryDSL is simply a generic query framework focused on building type-safe SQL queries through Java APIs. QueryDSL enables queries to be built in a common API manner on any supported ORM framework or SQL platform.

QueryDSL currently supports JPA,JDO,SQL,Java Collections,RDF,Lucene,Hibernate Search.

Therefore, QueryDSL used in our project is on top of JPA and introduced to supplement JPA's lack of complex query support.

3. So how do you manually execute this APT process alone?

The purpose of this consideration is actually to get more information. This step can be executed by right-clicking this option of Idea, or executing "mvn apt:process" in command.

You will notice the following warning in the output log

'build.plugins.plugin.version' for com.mysema.maven:apt-maven-plugin is missing. @ line 46, column 21

So add the latest version of plugin to pom configuration

1.1.3

Generate again, successfully generated!

At this point, I believe that everyone has a deeper understanding of "how Idea's GenerateSources cannot generate QueryDSL problems," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Tags: Query build framework support problem platform plug-in code file type project security necessity success that is information company content actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Technology MySQL macOS NVidia