renatoathaydes / ceylon-gradle-plugin

A simple Gradle plugin to manage Ceylon projects.
22 stars 6 forks source link

Project with multiple executables #27

Closed russel closed 7 years ago

russel commented 7 years ago

Is there an example of a project which is actually a collection of independent executables. I have the separate packages each with a run in a single module. Building it is easy. The problem is providing Gradle tasks so as to run the executables.

renatoathaydes commented 7 years ago

Check this build file:

https://github.com/renatoathaydes/ceylon-gradle-plugin/blob/master/ceylon-gradle-plugin-tests/module-with-tests-sample/build.gradle

Notice that you have an entryPoint you can set to any runnable function.

I suggest you use a project property to select which one you want to use, it works more or less like this:

def fun1Selected = project.hasProperty('fun1')
ceylon {
    if (fun1Selected) {
        entryPoint = 'fun1'
    }
}
gradlew runC -Pfun1

I don't have time to test right now, but something very similar to this should work.

russel commented 7 years ago

Thanks I will try going that route ­though I am hesitant as it will need every option hardwiring. I had been trying:

ext.programList = []

new File("${projectDir}/source/uk/org/winder/pi_quadrature").eachFileMatch(~/pi_.*/) { root ->
    final packageName = 'uk.org.winder.pi_quadrature.' + root.name
    ext.programList << 'run_' + root.name
    task ('run_' + root.name, type: JavaExec, dependsOn: 'compileCeylon') {
        main = packageName
        classpath = files('modules/uk/org/winder/pi_quadrature/1.0.0/uk.org.winder.pi_quadrature-1.0.0.car')
    }
}

task runAll (dependsOn: ext.programList)

and I am fairly sure this used to work, but now it is just failing with:

…
:run_pi_parallel_futures_loop
Error: Could not find or load main class uk.org.winder.pi_quadrature.pi_parallel_futures_loop
…
russel commented 7 years ago

Ah, it seems like the run mechanism in this Gradle plugin is not a JavaExec, but a run of the ceylon command as a subprocess, exactly as I had set up with my SCons build. I shall quit trying to find the right classpath!

russel commented 7 years ago

I have gone with:

final programList = new File("${projectDir}/source/${ceylon.module.replace('.', '/')}").listFiles({it.name.startsWith('pi_')} as FileFilter).collect{file ->
  final taskName = 'run_' + file.name
  task (taskName, type: Exec, dependsOn: 'compileCeylon') {
    commandLine '/usr/bin/env', 'ceylon', 'run', "--run=${ceylon.module}.${file.name}.run", ceylon.module
  }
  taskName
}

task runAll (dependsOn: programList)

which seems to work fine.

russel commented 7 years ago

I think with the official single entry point highlighted and two working solutions for the odd case of multiple entries working, this is a closeable issue. Thus I shall close it.

renatoathaydes commented 7 years ago

Did you try the createJavaRuntime task? If you use that, you can use JavaExec to run it (though this task creates a shell script to run the app, you can see what the shell script does to run the Ceylon code with java).

Also, we added support for Ceylon's own fatJar, which includes everything you need to run with java (so the two approaches are almost equivalent now).

russel commented 7 years ago

No and No. So now I have another couple of approaches to try, knowing I have something already, so they can be tried in a relaxed way. But tomorrow, for tonight it is quit working, eat and drink. :-)