• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

smartnews/jpa-entity-generator: Lombok-wired JPA entity source code generator, G ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

smartnews/jpa-entity-generator

开源软件地址(OpenSource Url):

https://github.com/smartnews/jpa-entity-generator

开源编程语言(OpenSource Language):

Java 97.9%

开源软件介绍(OpenSource Introduction):

jpa-entity-generator

Build Status Maven Central

This is a Java library which generates Lombok-wired JPA entity source code. The project provides Gradle plugin and Maven plugin.

Getting Started

build.gradle

apply plugin: 'java'

buildscript {
  dependencies {
    classpath 'com.h2database:h2:1.4.197'
    classpath 'com.smartnews:jpa-entity-generator:0.99.8'
  }
}

configurations { providedCompile }
sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile

repositories {
  mavenCentral()
}
dependencies {
  providedCompile 'org.projectlombok:lombok:1.18.2'
  providedCompile 'org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.0.Final'
}

apply plugin: 'entitygen'
entityGen {
    configPath = 'src/main/resources/entityGenConfig.yml'
}
For Maven users

Maven plugin to run the code generator is also available.

<plugin>
  <groupId>com.smartnews</groupId>
  <artifactId>maven-jpa-entity-generator-plugin</artifactId>
  <version>0.99.8</version>
  <dependencies>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.46</version>
    </dependency>
  </dependencies>
</plugin>

Put src/main/resources/entityGenConfig.yml, and then run the following command:

mvn jpa-entity-generator:generateAll

src/main/resources/entityGenConfig.yml

jdbcSettings:
  url: "jdbc:h2:file:./db/blog;MODE=MySQL"
  username: "user"
  password: "pass"
  driverClassName: "org.h2.Driver"

packageName: "com.example.entity"

If you need more examples, check the sample entityGenConfig.yml in this repository.

entityGen task

./gradlew entityGen compileJava

entityGen task generates entity classes for all the existing tables in the database.

package com.example.entity;

import java.sql.*;
import javax.persistence.*;
import lombok.Data;

@Data
@Entity(name = "com.example.entity.Blog")
@Table(name = "blog")
public class Blog {

  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  @Column(name = "\"id\"")
  private Integer id;
  @Column(name = "\"name\"")
  private String name;
  @Column(name = "\"active\"")
  private Byte active;
  @Column(name = "\"created_at\"")
  private Timestamp createdAt;
}

How to test on your local machine

To run the unit tests, simply run the following script as the TravisCI build does.

./test.sh

If you need to make sure if your latest code works with sample project or your existing projects, run the following command to publish the latest build to the local Maven repository.

./gradlew uploadArchives -Plocal

How to release new version

./gradlew clean uploadArchives
mvn deploy -Dmaven.test.skip=true



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
sormuras/modules: 发布时间:2022-08-17
下一篇:
samhitha1/demo: Sample for ANT/Maven Scripts发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap