Conditionally include exclude files while creating project using maven archetype

前端 未结 3 495
温柔的废话
温柔的废话 2021-02-04 10:06

Am trying to create an archetype which will conditionally include file based on the user input.

Like for eg., if a user will use this custom archetype and pass pa

3条回答
  •  清酒与你
    2021-02-04 10:45

    In case you want to remove a whole directory you can change the example above a little bit in order to achieve that! Here we go:

    import java.nio.file.Files
    
    // the path where the project got generated
    File rootDir = new File(request.getOutputDirectory() + "/" + request.getArtifactId())
    
    // the properties available to the archetype
    Properties properties = request.getProperties()
    String addSwaggerUI = properties.get("addSwaggerUI")
    
    // the Java package of the generated project, e.g. com.acme
    String packageName = properties.get("package")
    
    // convert it into a path, e.g. com/acme
    String packagePath = packageName.replace(".", "/")
    
    if (addSwaggerUI == "false") {
      println ""
      println "|---------> Hi there!"
      println "|-> ${rootDir}"
      println "|-> ${packageName}"
      println "|-> ${packagePath}"
      println "|-> ${addSwaggerUI}"
      println "|---------> Bye bye!"
      println ""
      new File(rootDir, "src/main/java/${packagePath}/config").deleteDir()
    }
    

    More archetype-post-generate.groovy examples can be found here and here!

提交回复
热议问题