Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle creating duplicate start scripts into bin directory

I am trying to create multiple start script files through gradle. But somehow one particular start script file is getting duplicated.

startScripts.enabled = false
run.enabled = false

def createScript(project, mainClass, name) {
  project.tasks.create(name: name, type: CreateStartScripts) {
    outputDir       = new File(project.buildDir, 'scripts')
    mainClassName   = mainClass
    applicationName = name
    classpath       = jar.outputs.files + project.configurations.runtime

     doLast {
            def windowsScriptFile = file getWindowsScript()
            def unixScriptFile    = file getUnixScript()
        windowsScriptFile.text = windowsScriptFile.text.replace('%APP_HOME%\\lib\\conf', '%APP_HOME%\\conf')
            unixScriptFile.text  = unixScriptFile.text.replace('$APP_HOME/lib/conf', '$APP_HOME/conf')
    }
  }
  project.tasks[name].dependsOn(project.jar)

  project.applicationDistribution.with {
    into("bin") {
      from(project.tasks[name])
      fileMode = 0755
    }
  }
}



// Call this for each Main class you want to expose with an app script
createScript(project, 'com.main.A', 'A')
createScript(project, 'com.main.B', 'B')

in bin directory I can see,

  • A.sh

  • A.sh

  • A.bat

  • A.bat

  • B.sh

  • B.bat

    What am I missing here? How to fix this?

Thank you for help.

like image 517
suraj_fale Avatar asked Sep 26 '22 07:09

suraj_fale


1 Answers

I solved this problem. Actually it was a mistake from my side and thanks to @Opal. I somehow forgot to delete 'mainClassName="com.main.A"' line from the header.

Also I have to add

distZip {
    duplicatesStrategy = 'exclude'
}
like image 173
suraj_fale Avatar answered Sep 30 '22 00:09

suraj_fale