Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle: custom jar task

Tags:

gradle

jar

I feel like I am missing something obvious here, but I can't seem to find it.

I have a project, where I want my package structure like so

/src
    /webapp
        /webapp-package-1
        /webapp-package-2
    /iface
        /iface-package-1
        /iface-package-2

I want to define a task that packages up the classes for iface and makes it into a jar. So I followed the user guide here: http://www.gradle.org/0.8/docs/userguide/userguide_single.html#configureSourceSet (I am using version 0.8).

I now have this,

sourceSets {
    main {
        java {
            srcDir 'src'
        }
        resources {
            srcDir 'src'
        }
    }
    intTest {
        java {
            srcDir 'src/iface/'
        }
        resources {
            srcDir 'src'
        }
    }
    test {
        java {
            srcDir 'test'
        }
        resources {
            srcDir 'src'
        }
    }
}


task intTestJar(type: Jar, dependsOn: intTestClasses) {
    from sourceSets.intTest.classes
}

And can verify that the classes in intTest are being built appropriately in /build/classes/intTest. However, trying to invoke the intTestJar always gives me this warning:

[ant:jar] Warning: skipping jar archive C:\workspace\foo\build\libs\foo-1.0.jar because no files were included.

I don't understand this, because the classes are being created successfully. Also, the full build task creates the entire jar successfully.

Ideas?

like image 423
lucas Avatar asked Aug 24 '26 15:08

lucas


1 Answers

This solution appears to work with the latest version of Gradle(0.9.2). I ran the intTestJar task exactly as shown above(adding the java plugin of course) on this file tree:

└── iface
    └── ifacePackageOne
        ├── Test.java
        └── testFile.txt

and here's the resulting jar structure:

├── META-INF
│   └── MANIFEST.MF
└── iface
    └── ifacePackageOne
        ├── Test.class
        └── testFile.txt

So the short answer - try a newer version of Gradle. http://gradle.org/

like image 200
TheKaptain Avatar answered Aug 27 '26 00:08

TheKaptain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!