Create Gradle Spring Boot project with SPRING INITIALIZR
I chose Groovy language for the project, but if you want Java, text below with little changes also helps you.
Edit build.gradle and add to it bootRun section
buildscript { ext { springBootVersion = '1.3.1.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'groovy' apply plugin: 'idea' apply plugin: 'spring-boot' jar { baseName = 'myapp' version = '0.0.1-SNAPSHOT' } sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } dependencies { compile('org.codehaus.groovy:groovy') testCompile('org.springframework.boot:spring-boot-starter-test') } task wrapper(type: Wrapper) { gradleVersion = '2.9' } // this code split parameters and allow us use parameters in our application bootRun { if ( project.hasProperty('args') ) { args project.args.split('\\s+') } }
create MyController class
@Controller class MyController implements CommandLineRunner { private Logger logger = LoggerFactory.getLogger(this.getClass()) @Override void run(String... args) throws Exception { if(!args) { logger.warn("You must pass at least one parametr.") logger.warn("Example: bootRun -Pargs=\"arg1 arg2 arg3\"") } // print parameters which we sent from command line args.each{ arg -> logger.info(arg) } } }
Run application
gradle bootRun -Pargs=”arg1 arg2 arg3″