spg

SPG is simple terminal tool for generating SpringBoot package and Classes easily and quickly.
.
Why Spg?
If you want to generate SpringBootPackage , you can take 2 ways
mvn commands
But, mvn commands needs lots of typing and generated package is only JavaPackage, it is not SpringBootPackage .
Spring-initializr
Spring-initializr is a good way of generating SpringBootPackage.
But Spring-initializr can be only used on online.
Also,what Spring-initializr do about dependency is only adding dependency tag on pom.xml in many case.
So, If you add dependency on Spring-initializr and download it, its package may imcomplete one .
Then, What I want is this. Spg is this.
- Cli which only takes
few typing
- Generate SpringBootPackage .
- Can be used offline.
- Generate completed application depends on what function (ex, API, DB, Scheduler) we want to use .
To do that, I make spg commands.
Usage
Generate Package
you can generate SpringBoot package with below command very quickly.
spg gen -g "com.sample" -a "sampleproject" -name "sample-project"
then, you can generate SpringBootPackage like this.
├── pom.xml
└── src
├── main
│ ├── java
│ │ └── com
│ │ └── sample
│ │ └── sampleproject
│ │ └── SampleProject.java
│ └── resources
│ └── application.properties
└── test
└── java
└── com
└── sample
└── sampleproject
└── SampleProjectTests.java
This is the basic components of SpringBootPackage .
you can also generate SpringBootPackage from .toml file.
$ spg genf test.toml
Generating package spring-boot-generator !
.toml file formats are below.
toml Setting file
you should touch .toml file to select what kinds of Java-Class files you want to generate automatically.
Here is the example of generating DB-related file.
[App]
name="spring-boot-generator"
groupId="com.kcwebapply"
artifactId="spring-sample"
[Db]
jdbc="jdbc:postgresql://localhost:5432/test"
driver="org.postgresql.Driver"
table="Purchase"
Then, after we run spg command, we generate package anc classes .
Generated package constitution
In this case, package constitution is like this.
|--pom.xml // generated automatically by default (some dependency added automatically ).
|--src
| |--main
| | |--java
| | | |--com
| | | | |--kcwebapply
| | | | | |--springsample
| | | | | | |--SpringBootGenerator.java // generated automatically by default.
| | | |--model
| | | | |--PurchaseEntity.java // entity generated by Db setting (refer to Db.Table key on toml file).
| | | | |--PurchaseRepository.java // repository generated by Db setting (refer to Db.Table key on toml file).
| | |--resources
| | | |--application.properties // generated automatically by default.
| |--test
| | |--java
| | | |--com
| | | | |--kcwebapply
| | | | | |--springsample
| | | | | | |--SpringBootGeneratorTests.java // generated automatically by default.
As you see, this command generate the basic constitution of SpringBoot package.
The most remarkable feature is that this library generate Entity class and Repository interface.
@Entity
@Table(name="Purchase")
public class PurchaseEntity {
}
@Repository
public interface PurchaseRepository extends JpaRepository<PurchaseEntity,String> {
}
This command generate these boilerplate class about foundational function on SpringBoot .
application.properties
Depending on what you write on .toml file, some property is also written on application.properties automatically.
application.properties is also modified to adapt you setting.
spring.datasource.url=jdbc:postgresql://localhost:5432/test
spring.datasource.driver-class-name=org.postgresql.Driver
pom.xml
You add database setting on your .toml file, so then some dependency is added to pom.xml automatically.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Like this, when you write some library setting on .toml file,
dependency package is also added automatically.
Generating toml file
you can generate .toml file with spg touch command.
$ spg touch -artifactId spring-boot-generator -g com.test -n spring-boot-generator
Generating spg.toml file completed!
generate file like this.
// spg.toml
[App]
name="spring-boot-generator"
groupId="com.test"
artifactId="spring-boot-generator"
springVersion="2.1.1.RELEASE"
javaVersion="1.8"
supported function
Here is the list of supported function and .toml setting.
SpringDataJpa (Mysql, postgres)
[Db]
jdbc="jdbc:postgresql://localhost:5432/test"
driver="org.postgresql.Driver"
table="Purchase"
SpringScheduler
[task]
schedule = "0 * * * * *"
zone="Asia/Tokyo"
Install
On macOS
brew tap kcwebapply/spg
brew install spg