GitHub - smartnews/jpa-entity-generator: Lombok-wired JPA entity source code generator, Gradle and Maven supported.

jpa-entity-generator

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

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

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'}

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

Maven plugin to run the code generator is also available.


  com.smartnews
  maven-jpa-entity-generator-plugin
  0.99.6
  
    
      mysql
      mysql-connector-java
      5.1.46
    
  

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.ymlin this repository.

  • https://github.com/smartnews/jpa-entity-generator/tree/master/src/test/resources/entityGenConfig.yml

entityGen task

./gradlew entityGen compileJava

entityGentask generates entity classes for all the existing tables in the database.

packagecom.example.entity;importjava.sql.*;importjavax.persistence.*;importlombok.Data;@[email protected](name="com.example.entity.Blog")@Table(name="blog")publicclassBlog{@[email protected](strategy=GenerationType.IDENTITY)@Column(name="\"id\"")privateIntegerid;@Column(name="\"name\"")privateStringname;@Column(name="\"active\"")privateByteactive;@Column(name="\"created_at\"")privateTimestampcreatedAt;
}

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

你可能感兴趣的:(GitHub - smartnews/jpa-entity-generator: Lombok-wired JPA entity source code generator, Gradle and Maven supported.)