Spicy Spring: Create New Projects From a URL
To quickly start with a Spring project we can use the website start.spring.io.
Via a user interface we can set project properties and at the end we have a project archive (Zip or gzipped Tar file) or build file (pom.xml or build.gradle
).
We can also directory access an URL to create the output files and we set the properties via request parameters.
This way you can share a link with someone and if they click on it they will download the generated project archive or build files.
We can choose different base URLs depending on the type of project archive we want.
To get a Zip file we use http://start.spring.io/starter.zip
and to get a gzipped Tar file we use http://start.spring.io/starter.tgz
.
To create a Gradle build file with all the configuration for a project we use http://start.spring.io/build.gradle
.
For a Maven POM XML file we use the URL hhttp://start.spring.io/pom.xml
.
All output format support the same request parameters to set the project properties:
Request parameter
Description
Sample
dependencies
Add Spring Boot Starters and dependencies to your application
web,security
style
Alias for dependencies
actuator,sleuth,eureka&20discovery
type
Used for project archives. Use gradle-project
or maven-project
gradle-project
name
Name of project
demo
description
Description for the project
Demo%20project%20for%20Spring%20Boot
groupId
Value for groupId for publishing project
com.example
artifactId
Value for artifactId for publishing project
demo
version
Version of the project
1.0.0.DEVELOPMENT
bootVersion
Version for Spring Boot
1.3.3
packaging
Packaging for project (jar
or war
)
jar
applicationName
Name of the application
demo
language
Language can be Java
, Groovy
or Kotlin
Groovy
packageName
Name for package for example code
com.example
javaVersion
Java version for project
1.8
baseDir
Base directory in archive
sample
Let's create a URL for a Groovy project with a Gradle build file where we have a dependency on web
, security
and actuator
:
http://start.spring.io/build.gradle?dependencies=web,security,actuator&name=sample&description=Sample&20Project&version=1.0.0.DEVELOPMENT&bootVersion=1.3.3.RELEASE&javaVersion=1.8&language=groovy&packaging=jar
When we save the Gradle build file we have the following file contents:
buildscript {
ext {
springBootVersion = '1.3.3.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'spring-boot'
jar {
baseName = 'demo'
version = '1.0.0.DEVELOPMENT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.codehaus.groovy:groovy')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.9'
}
Instead of just a build file we want to create a sample project archive file. We use the following URL:
http://start.spring.io/starter.tgz?dependencies=web,security,actuator&name=sample&description=Sample&20Project&version=1.0.0.DEVELOPMENT&bootVersion=1.3.3.RELEASE&javaVersion=1.8&language=groovy&packaging=jar&type=gradle-project&baseDir=sample
Let's open the archive and see the contents. Notice we used the baseDir
request parameter so when we unpack we get a new directory.
$ tar xf starter.tgz
$ tree sample/
sample/
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
├── main
│ ├── groovy
│ │ └── com
│ │ └── example
│ │ └── SampleApplication.groovy
│ └── resources
│ ├── application.properties
│ ├── static
│ └── templates
└── test
└── groovy
└── com
└── example
└── SampleApplicationTests.groovy
14 directories, 8 files
$
Written with Spring Boot 1.3.3.