Coder Social home page Coder Social logo

Comments (12)

townsfolk avatar townsfolk commented on August 16, 2024

Hmm. Assuming you have the import statement, in your build script, it should work.

You can try using the full classname:
String projectName = templates.TemplatesPlugin.prompt('Project Name:')

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

I get the same error

I am new to groovy programming. I have placed the grade-templates-1.3.jar under <gradle_installation>/lib and also under <gradle_installation>/lib/plugins .
I am using gradle 1.4

gradle createMyProject
:createMyProject FAILED

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Users//Desktop/sample_projects/try_out_gradle_templates/build.gradle' line: 13

  • What went wrong:
    Execution failed for task ':createMyProject'.

    Could not find property 'templates' on task ':createMyProject'.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.643 secs

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

In order to import classes within build script is there any other setting to be done ?

This might be a basic question - appreciate your help in getting this resolved.

from gradle-templates.

townsfolk avatar townsfolk commented on August 16, 2024

That method of installation doesn't work with Gradle 1+. Actually, could you please tell me where you learned of that method? It's been removed from the project home page, and the old wiki location points to the new project home page. Would like to figure out if I missed some documentation somewhere. :)

You need to use the "apply from" method described on the project home page: https://github.com/townsfolk/gradle-templates

Basically, your build.gradle file should look something like this:

apply from: 'http://www.tellurianring.com/projects/gradle-plugins/gradle-templates/apply.groovy'

import templates.*
task 'createMyProject' << {
    String projectName = TemplatesPlugin.prompt('Project Name:')
    ProjectTemplate.fromRoot(projectName) {
        'src/com/example' {}
        'build.gradle' '''
        apply plugin: 'java'
        sourceSets {
            main {
                java {
                    srcDir 'src'
                }
            }
        }
        '''
    }
}

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

I have cut and pasted the same build.gradle and get the error again.

I tried the below settings in init.gradle
gradle.beforeProject { prj ->
prj.apply from: 'http://www.tellurianring.com/projects/gradle-plugins/gradle-templates/apply.groovy'
}
but get the same error.

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

Reg the method of installation , I just tried few other means of installing the plugins from different forums. Your documentation is clear.

from gradle-templates.

townsfolk avatar townsfolk commented on August 16, 2024

Custom project structures won't work with the global install. You might be able to add createMyProject task within the init.gradle script, not sure if that'll work.

prj.task "createMyProject" << { .... }

I am seeing the same error you are now. Not sure what's broken, but I'll get back to you.

Thanks!

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

Thanks a lot as this would be very useful in our project.

from gradle-templates.

townsfolk avatar townsfolk commented on August 16, 2024

Looks like the apply script no longer adds the classes to your build script. I can't find another workaround besides putting the contents of the apply script directly into your build script.

If you want your 'createMyProject' task, and all the other templates, replace the 'apply from' line with the following:

buildscript {
    repositories {
        ivy {
            name = 'gradle_templates'
            artifactPattern 'http://tellurianring.com/projects/gradle-plugins/[module]/[revision]/[artifact]-[revision].[ext]'
            ivyPattern 'http://tellurianring.com/projects/gradle-plugins/[module]/[revision]/[artifact]-[revision].[ext]'
        }
    }
    dependencies {
        classpath 'gradle-templates:gradle-templates:1.3'
    }
}
// Check to make sure templates.TemplatesPlugin isn't already added.
if (!project.plugins.findPlugin(templates.TemplatesPlugin)) {
    project.apply(plugin: templates.TemplatesPlugin)
}

If you don't want the other templates, you can remove the final if check:

buildscript {
    repositories {
        ivy {
            name = 'gradle_templates'
            artifactPattern 'http://tellurianring.com/projects/gradle-plugins/[module]/[revision]/[artifact]-[revision].[ext]'
            ivyPattern 'http://tellurianring.com/projects/gradle-plugins/[module]/[revision]/[artifact]-[revision].[ext]'
        }
    }
    dependencies {
        classpath 'gradle-templates:gradle-templates:1.3'
    }
}

Either of these will work for creating your own tasks, you only need the if check if you want to use the base templates as well.

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

Thanks. I will try this.

from gradle-templates.

townsfolk avatar townsfolk commented on August 16, 2024

I'm going assume this issue is closed, please reopen if you still experience issues.

from gradle-templates.

lives78 avatar lives78 commented on August 16, 2024

Thanks. Its working. This was really useful.
The issue can be closed.

from gradle-templates.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.