Gradle counterpart to Maven archetype?

2019-01-31 16:57发布

问题:

What is the Gradle counterpart to Maven archetypes? How can I give other Gradle users a template for the file and directory layout for a new project?

回答1:

Gradle doesn't support this (yet). There's a open feature request opened already.



回答2:

Use build init plugin:

~$ mkdir newproj
~$ cd newproj
~/newproj$ gradle init --type java-library

At the moment java-library, scala-library, groovy-library, java-application, pom and basic supported. The feature is incubating, thus it can be changed in future releases, so keep an eye on docs.



回答3:

While this is not yet supported by Gradle, the gradle:templates plugin looks promising:



回答4:

Gradle don't support build-in archetype-like feature, but you can use plug-in named Gradle templates

Read more:
Does gradle have Maven archetype-like functionality?
Gradle archetypes issue



回答5:

There is no gradle counterpart as far as I know. However following the steps given below is enough for most cases:

  • Generate project with maven and your selection of maven archetype.
  • Convert the maven project to gradle project. You can do that by executing the below command in the directory where your master pom.xml is located:

    gradle init

Its supposed to work with all basic maven archetypes.



回答6:

I'm been looking for this feature as well, and found that it's a little bit complicated to have a complex project template to work with https://github.com/townsfolk/gradle-templates.

So I created this plugin, it's quite similar with the Maven archetype function. https://github.com/orctom/gradle-archetype-plugin/



回答7:

In case you are using the spring framework under Linux: You could use http://start.spring.io/ or alternatively install Spring CLI

$ curl -s "https://get.sdkman.io" | bash

$ sdk install springboot

$ spring --version
Spring Boot v1.3.5.RELEASE

$ spring init --build gradle --name test --groupId com.test
Using service at https://start.spring.io
Content saved to 'demo.zip'

$ unzip demo.zip 


回答8:

You can create generators for Yeoman, or use existing non-official ones such as JHipster. As an example there is the java-gradle generator:

  1. npm install -g yo
  2. Install module globally: npm install -g generator-java-gradle
  3. Generate project with: yo java-gradle