プロジェクトクラスパスから Entity の superclassName を解決できるようにする#294
Open
tomo-yamaguchi-cre wants to merge 2 commits intodomaframework:masterfrom
Open
プロジェクトクラスパスから Entity の superclassName を解決できるようにする#294tomo-yamaguchi-cre wants to merge 2 commits intodomaframework:masterfrom
tomo-yamaguchi-cre wants to merge 2 commits intodomaframework:masterfrom
Conversation
- Add codegen-superclass-test module to test entity superclass functionality - Implement AbstractEntity with common audit fields (createdBy, createdAt, etc.) - Implement AbstractEntityListener for automatic audit field population - Add test database schema with EMPLOYEE, DEPARTMENT, and PROJECT tables - Configure domaCodeGen to use custom superclass and listener - Add DAO tests to verify generated code with superclass The test demonstrates: - Loading superclass from project's compiled classes via domaCodeGen classpath - Three-phase build: compile base classes → generate code → compile all - Generated entities properly extend AbstractEntity - Generated listeners extend AbstractEntityListener
- Add ClassLoader provider in CodeGenConfig to resolve classes from domaCodeGen configuration - Pass ClassLoader to CodeGenEntityDescTask for loading entity superclass - Use custom ClassLoader in ClassUtil.forName when resolving superclass - Enables loading user-defined superclasses from build classpath This change allows the plugin to resolve entity superclass and listener superclass from the domaCodeGen configuration classpath, rather than only from the plugin's own classpath.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
こんにちは。
Ant ベースの doma-gen から Gradle の doma-codegen-plugin へ移行する中で、エンティティ生成時に
superclassNameで指定したプロジェクト内クラスを解決できず、以下のエラーになる問題に遭遇しました。プロジェクト内で定義したスーパークラス(例: AbstractEntity)を superclassName に指定したい場面があるのですが、現状はコード生成タスクの ClassLoader がプロジェクトのビルド出力や domaCodeGen 構成のクラスパスを参照しないため、解決できませんでした。
また、docs/codegen.md には superclassName の設定例がある一方で、プロジェクト内クラスを参照する場合のクラスパス設定については補足がなく、この挙動に気づきにくいかもしれないと感じました。
このPRでは、プロジェクトクラスパスを使って
superclassNameを解決できるように対応します。変更内容
domaCodeGen構成のクラスパス等を含む ClassLoader を遅延評価で作成できるようにしました(設定フェーズでの解決を避けるため)。connectProperties()で上記 Provider を各タスクに渡すようにしました。codegen-superclass-testモジュールで、監査フィールドを持つAbstractEntityをsuperclassNameに指定しエンティティが生成できることを確認しています。使い方(例)
プロジェクト内のスーパークラスを参照したい場合、以下のように
domaCodeGen構成へプロジェクト出力を追加できるようになります。dependencies { domaCodeGen(libs.h2) domaCodeGen(sourceSets.main.get().output) }必要に応じて、コード生成タスクより先にスーパークラスがコンパイルされるよう依存関係を調整する必要があります。
後方互換性
ClassLoader を明示的に提供しない場合は、これまで通りプラグインの ClassLoader を使用するため、既存設定への影響はありません。