Gradle
  1. Gradle
  2. GRADLE-1289

Provide a "create-project" command to create a skeleton project directory.

    Details

    • Type: New Feature New Feature
    • Status: Resolved Resolved
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.7-rc-1

      Description

      Please see http://gradle.1045684.n5.nabble.com/Gradle-first-steps-and-create-project-td3315373.html

      It would be good to have some way of conveniently creating a skeleton project (similar to the way "grails create-app" works, for example).

      This would create the directory structure and maybe an example "HelloWorld" app for the user to customise.

      You'd probably need separate options for Java, Groovy and Scala programs (the link above mentions some options).

        Activity

        Hide
        Leonard Brünings
        added a comment - - edited

        The Script below will create the src file structure for a new project based on the used plugins.
        (Tested with gradle-1.0-milestone1)

        build.gradle
        apply plugin: 'java'
        apply plugin: 'groovy'
        apply plugin: 'scala'
        
        task initProjectStructure () << {
        	project.sourceSets.all*.allSource.sourceTrees.srcDirs.flatten().each { dir ->
        		dir.mkdirs()
        	}
        }
        
        improved version, call from cmdline
        task initProject () << {
        	if (hasProperty(initPlugins)) {
        		initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } }
        	}	
        
        	project.sourceSets.all*.allSource.sourceTrees.srcDirs.flatten().each { dir ->
        		dir.mkdirs()
        	}
        }
        

        You could execute this with gradle.bat initProject -PinitPlugins=Java,Groovy,Scala

        Show
        Leonard Brünings
        added a comment - - edited The Script below will create the src file structure for a new project based on the used plugins. (Tested with gradle-1.0-milestone1) build.gradle apply plugin: 'java' apply plugin: 'groovy' apply plugin: 'scala' task initProjectStructure () << { project.sourceSets.all*.allSource.sourceTrees.srcDirs.flatten().each { dir -> dir.mkdirs() } } improved version, call from cmdline task initProject () << { if (hasProperty(initPlugins)) { initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } } } project.sourceSets.all*.allSource.sourceTrees.srcDirs.flatten().each { dir -> dir.mkdirs() } } You could execute this with gradle.bat initProject -PinitPlugins=Java,Groovy,Scala
        Hide
        Keith Koski
        added a comment -

        I tried improved version with 1.0-milestone-4. It fails with "Could not find property 'sourceSets' on root project 'fff'."

        Show
        Keith Koski
        added a comment - I tried improved version with 1.0-milestone-4. It fails with "Could not find property 'sourceSets' on root project 'fff'."
        Hide
        Peter Niederwieser
        added a comment -

        Have a look at the Templates plugin: https://launchpad.net/gradle-templates

        Show
        Peter Niederwieser
        added a comment - Have a look at the Templates plugin: https://launchpad.net/gradle-templates
        Hide
        Steve Olsen
        added a comment -

        I've been looking for this capability everywhere. Maven does this, why not Gradle?

        Show
        Steve Olsen
        added a comment - I've been looking for this capability everywhere. Maven does this, why not Gradle?
        Hide
        Adam Murdoch
        added a comment -

        @steve, there's no good reason, other than we haven't gotten around to it yet. Hopefully soon after Gradle 1.0 is released, we will tackle this problem.

        Show
        Adam Murdoch
        added a comment - @steve, there's no good reason, other than we haven't gotten around to it yet. Hopefully soon after Gradle 1.0 is released, we will tackle this problem.
        Hide
        mark petrovic
        added a comment -

        I'm interested in this feature, which will really help newcomers get started quickly in creating new projects.

        Show
        mark petrovic
        added a comment - I'm interested in this feature, which will really help newcomers get started quickly in creating new projects.
        Hide
        Lukas Bradley
        added a comment -

        I've updated Leonard's script above to work with 1.2.

        apply plugin: 'java'
        
        task initProject () << {
        	if (hasProperty(initPlugins)) {
        		initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } }
        	}	
        
        	project.sourceSets*.allSource.srcDirTrees.flatten().dir.each { dir ->
        		dir.mkdirs()
        	}
        }
        
        Show
        Lukas Bradley
        added a comment - I've updated Leonard's script above to work with 1.2. apply plugin: 'java' task initProject () << { if (hasProperty(initPlugins)) { initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } } } project.sourceSets*.allSource.srcDirTrees.flatten().dir.each { dir -> dir.mkdirs() } }
        Hide
        Michael Peterson
        added a comment - - edited

        I'm new to gradle, but none of the above examples work for me as written.

        For just Java, you have to issue this cmd: gradle initProject -PinitPlugins=java (Note: lowercase 'j')

        or change this line:
        initPlugins.split(',').each { plug -> project.apply

        { plugin(plug.trim()) }

        }

        to:
        project.apply

        { plugin('java') }

        and then just do:
        gradle initProject

        from the cmd line

        +1 for getting this feature added quickly.

        Show
        Michael Peterson
        added a comment - - edited I'm new to gradle, but none of the above examples work for me as written. For just Java, you have to issue this cmd: gradle initProject -PinitPlugins=java (Note: lowercase 'j') or change this line: initPlugins.split(',').each { plug -> project.apply { plugin(plug.trim()) } } to: project.apply { plugin('java') } and then just do: gradle initProject from the cmd line +1 for getting this feature added quickly.
        Hide
        Adam Murdoch
        added a comment -

        Gradle 1.6 and 1.7 add some support for setting up a new Gradle build using the `build-setup` plugin.

        This initial support is very basic and we want to grow it in future releases, but I've marked this issue as 'fixed'. If you find problems or have suggestions for improvements to this build initialization support, please feel free to raise new issues via the forums.

        You can find out more about our plans in this design spec: https://github.com/gradle/gradle/blob/master/design-docs/build-initialisation.md

        Show
        Adam Murdoch
        added a comment - Gradle 1.6 and 1.7 add some support for setting up a new Gradle build using the `build-setup` plugin. This initial support is very basic and we want to grow it in future releases, but I've marked this issue as 'fixed'. If you find problems or have suggestions for improvements to this build initialization support, please feel free to raise new issues via the forums. You can find out more about our plans in this design spec: https://github.com/gradle/gradle/blob/master/design-docs/build-initialisation.md
        Hide
        Marcel Overdijk
        added a comment -

        Looking at the build-setup plugin, am I right there is support (yet) for custom templates?

        Show
        Marcel Overdijk
        added a comment - Looking at the build-setup plugin, am I right there is support (yet) for custom templates?
        Hide
        Adam Murdoch
        added a comment -

        @Marcel, that's correct. The plan is to add support for this over time.

        Show
        Adam Murdoch
        added a comment - @Marcel, that's correct. The plan is to add support for this over time.

          People

          • Assignee:
            Unassigned
            Reporter:
            Paul Cager
          • Votes:
            43 Vote for this issue
            Watchers:
            34 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: