gradleweblogic12cjava-ee-7lazybones

How do I get Lazybones to create Multi Modular Java EE 7 Gradle Projects?


This is my repository in github: https://github.com/joedayz/lazybones-templates/

I used processTemplates according with the documentation

processTemplates 'build.gradle', props
processTemplates 'gradle.properties', props
processTemplates 'src/main/java/*.java', props
processTemplates 'settings.gradle', props

I request the user this information:

    props.project_megaproceso = ask("Define value for 'megaproceso'  [megaproceso]: ", "megaproceso", "megaproceso")
    props.project_macroproceso = ask("Define value for 'macroproceso' [macroproceso]: ", "macroproceso", "macroproceso")
    props.project_proceso = ask("Define value for 'proceso' [proceso]: ", "proceso", "proceso")

megaproceso2, macroproceso, proceso are directories or part of file names in my template.

How do I change the names of the unpacked directories and files? The code is in my github.


Solution

  • The post-install scripts for Lazybones currently have full access to both the standard JDK classes and the Apache Commons IO library, specifically to aid with file manipulation.

    In this specific case, you can either use File.renameTo() or FileUtils.moveFile/Directory(). For example:

    def prevPath = new File(projectDir, "megaproceso2-macroproceso-proceso.ear")
    prevPath.renameTo(new File(
        projectDir,
        "${props.megaproceso}-${props.macroproceso}-${props.processo}.ear"))
    

    The projectDir variable is one of several properties injected into the post-install script. You can find a list of them in the Template Developers Guide.

    I think the main advantage of FileUtils.moveFile() is that it works even if you're moving files across devices, but that's not necessary here. Also note that you have to explicitly import the classes from Commons IO if you want to use them.