Gradle task Orgnaization

Sorry for the delay. It’s possible, but it’s slightly more complicated:

repositories {
    mavenCentral()
}
configurations {
    configFiles {
        transitive = false
    }
}
dependencies {
    configFiles 'my.group.id:my.artifact.id:0.0.0'
}

def myJar = configurations.configFiles.files.first()
def xmlFiles = zipTree(myJar).matching { include 'config/spring/**/*.xml' }

xmlFiles.each { file ->
    def fileNameWithoutExtension = file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}
    def taskName = "run$fileNameWithoutExtension"
    
    task(taskName, type: MyRunTask) {
        main = 'main.Startup'
        xmlFile = file.name
    }
    
    runAll.dependsOn taskName
}

Here we’re creating a custom configuration to store the necessary Jar files. I’ve set it as not transitive to avoid downloading all dependencies of the Jar, but you might want to download the dependencies too. Then I configured the Jar with the XML files as a dependency for the custom configuration. Finally, I used the configuration so that Gradle downloads the Jar file automatically, and expands it as necessary so we can load the XML files.

Hope this helps :slight_smile:

I have tried this option but it is still not taking xml files from jar files. Anyway I moved xml files to gradle folder and it works now.

Thanks and appreciate your help

BTW: I am running 100 JVM java processes in proof of concept. Do you know any free monitoring tool which I can use to monitor these processes

Is your Jar file with the XML files public? If you have a Maven group/artifact/version string you can send me, I can try it out over here to see if I can get it to run.

Regarding the JVM processes, unfortunately I have no idea . I don’t think I’ve executed that many processes in parallel before. Perhaps someone from Gradle has done something similar before?

It is working now. I have specified the wrong project. Thanks and appreciate your help

Great :smiley: No problem!

Now I would like to run java program from a directory e.g. com.test.HelloWorldA, com.test.HelloWrorldB. Basically the mainclass name is different for each.

Is is possible to change mainclass name as well in a loop?

It’s possible, you only need to specify how each main class name is different.

For example, you could use the same code used to obtain the run tasks from the XML files, and set the main property for each task.

Or, if this is totally unrelated to the XML files, you can specify a list of main classes and create tasks for them, just as before:

['A', 'B'].each { name ->
    task("runWith$name", type: JavaExec) {
        classpath = sourceSets.main.runtimeClasspath
        main = "com.test.HelloWorld$name"
    }
}

Did I understand you question correctly?

Yes Great Help. Yes you understand the question correctly

Ok, I’m happy to have been able to help :slight_smile: