# g2rain-crafter(Maven 代码生成插件)

g2rain-crafter 是一个 Maven 插件,用于根据 codegen.properties 中的数据库与表配置,生成符合平台规范的项目骨架与业务代码。文档主要以“配置文件 + 安装方式 + 执行方式”的结构组织。

# 配置文件:codegen.properties

插件依赖 codegen.properties 配置文件,并要求放置在项目根目录。示例:

# 项目配置
archetype.package=com.g2rain.demo

# 数据库配置
database.url=jdbc:mysql://localhost:3306/g2rain-demo?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
database.driver=com.mysql.cj.jdbc.Driver
database.username=root
database.password=root123456

# 待生成表
database.tables=user,product,trade

# 文件覆盖控制
tables.overwrite=false

codegen.properties 必须放置在项目根目录,并确保数据库信息正确。

# 安装插件(在业务项目 POM 中添加)

在业务项目(父工程或根模块)中引入:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>com.g2rain</groupId>
      <artifactId>g2rain-crafter</artifactId>
      <version>1.0.2</version>
      <configuration>
        <phase>foundry</phase>
        <configFile>${project.basedir}/codegen.properties</configFile>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

<plugin>
  <groupId>com.g2rain</groupId>
  <artifactId>g2rain-crafter</artifactId>
  <!-- 根模块执行,避免子模块自动继承 -->
  <inherited>false</inherited>
  <executions>
    <execution>
      <id>bootstrap-execution</id>
      <phase>none</phase>
      <goals>
        <goal>bootstrap</goal>
      </goals>
    </execution>
  </executions>
</plugin>

# 使用方式

在项目根目录执行(示例):

mvn com.g2rain:g2rain-crafter:1.0.2:bootstrap -Dphase=foundry