The New Software Model and Applications

Hiya,
I’ve been trying out the Gradle nightly builds and have created my own multiple component project using the new Software Model.

Now I would like to define an ‘application’, to use all these lovely libraries built based on the model,
and I notice that ApplicationSpec is not a valid component type for the model at the moment?
If I try the old way, and use the ‘application’ plugin, it doesn’t seem to know about the libraries I have already built (i.e. it seems to try to build+need dependency info again)?

I know this is all in flux at the moment, but in the interim, what is the recommended approach for being able to ‘run’ my applications main() method from Gradle when using the new software model?

Many thanks for your time,

Jez.

This is something we plan to support in the software model as a first class citizen. The idea being that there would be some kind of JvmApplicationSpec that would natively support toolchains, etc. For now you can wire up a JavaExec task manually. Here’s a simple example.

apply plugin: 'jvm-component'
apply plugin: 'java-lang'

model {
    components {
        main(JvmLibrarySpec)
    }
    tasks {
        run(JavaExec) {
            dependsOn $.binaries.mainJar.getTasks().getJar()
            classpath = files($.binaries.mainJar.getJarFile())
            main = 'Main'
        }
    }
}

Perfect! Thanks for the example Mark, much appreciated.

Cheers,

Jez.

Hiya,
Thanks for your earlier help,
Do I need to declare every dependency, or can a task pick up the dependencies on libraries in (new model) subprojects transitively?

For example, how do I declare that the run task has a dependency when running on a (new model) library called ‘gnar’ in a subproject called ‘fluffy’?

build.gradle

apply plugin: 'jvm-component'
apply plugin: 'java-lang'
model {
    components {
        main(JvmLibrarySpec) {
            sources {
                java {
                    dependencies {
                        project ':fluffy' library 'gnar'
                    }
                }
            }
        }
    }
    tasks {
        run(JavaExec) {
            dependsOn $.binaries.mainJar.getTasks().getJar()
            dependsOn  '<-------* How to specify library in a subproject???'
            classpath = files($.binaries.mainJar.getJarFile(), '<--* also what goes here for library in subproject?')
            main = 'Main'
        }
    }
}

fluffy/build.gradle

model {
    components {
        gnar(JvmLibrarySpec) {
            api {
                exports 'com.example'
            }
        }
    }
}

Also, I can’t seem to find what the 'Reference $.’ actually means, it looks like a reference to the model, does it have some documentation? for example in the $.binaries… bit above. (Started trying to use projects(':fluffy').binaries... in place, to no avail.)

Thanks

Jez.