2010/7/28 Adam Murdoch <[email protected]>

>  On 27/07/10 3:04 PM, Alessandro Marino wrote:
>
>> Hello,
>> I'm trying to write a build script that compiles some classes and put them
>> togheter with a few resources.
>> The resources are composed by: all files in the 'images' directory and a
>> few files in the root directory.
>>
>> I would like to mantain the same layout also in the resulting jar.
>>
>> $ cat build.gradle
>> usePlugin 'java'
>>
>> version = '4.1.1'
>>
>> sourceSets {
>>        main {
>>                java {
>>                    srcDir 'src'
>>                }
>>                resources {
>>                    srcDirs 'images'
>>                    destinationDir file('images')
>>                }
>>        }
>> }
>>
>> defaultTasks  'jar'
>>
>> After executing this script I get:
>>
>> FAILURE: Build failed with an exception.
>>
>> * Where:
>> Build file '/home/alexyz/schemas/build.gradle' line: 12
>>
>> * What went wrong:
>> A problem occurred evaluating root project 'schemaSpy'.
>> Cause: Could not find method destinationDir() for arguments
>> [/home/gbs00819/schemas/images] on source set main.
>>
>> * Try:
>> Run with -s or -d option to get more details. Run with -S option to get
>> the full (very verbose) stacktrace.
>>
>> BUILD FAILED
>>
>> Total time: 4.16 secs
>>
>> How can I define to include all file under 'images' preserving the folder?
>> The script doesn't address the requirement to include some files in the
>> project's root directory also in the jar. How can I do that?
>>
>
> There's a couple of options. One is:
>
> sourceSets {
>    main {
>        resources {
>            srcDir projectDir
>            include 'images/**'
>            include 'someFileInTheRootDir'
>            include 'someOtherFileInTheRootDir'
>        }
>   }
> }
>
> The other is to get rid of the resources { } section, and configure the
> processResource task directly:
>
> processResources {
>    from(projectDir) {
>        include 'images/**'
>        include 'someFileInTheRootDir'
>
>    }
> }
>

Thanks a lot Adam for your help!

Unfortunately I forgot that I need also to include some properties file that
are mixed with classes, to do that I've added a second "from" closure:

sourceSets {
        main {
                java {
                        srcDir 'src'
                }
                processResources {
                        from(projectDir) {
                                include 'images/**'
                                include 'jquery*'
                        }
 from(projectDir + '/src') {
                                include '**/*.properties'
                        }
                }
        }
}

Obviously (because I'm not as smart as Gradle :-) ) I get an exception:

$ gradle

FAILURE: Build failed with an exception.

* Where:
Build file '/home/alexyz/schemas/build.gradle' line: 10

* What went wrong:
A problem occurred evaluating root project 'schemaSpy'.
Cause: Could not find method processResources() for arguments
[build_gradle_2bedb9b09af44a1d2902600ce653da5b$_run_closure1_closure2_closu...@efeff8]
on source set main.

How can I cope with this error?

Thanks and regards,
Alessandro

Reply via email to