hdockter wrote:
> 
> 
> On Jul 2, 2008, at 10:03 AM, Dominick More wrote:
> 
>>
>> While evaluating Gradle I've run into a dead end with the usage of  
>> the war
>> plugin. The "usePlugin('war')" directive is in the file
>> ./csl/wars/build.gradle but the war file source is actually in
>> ./csl/wars/mywarproject and dependencies are defined in
>> ./csl/wars/mywarproject/build.gradle
>>
>> Two things stump me with the war file:
>>
>> 1) Files not within the war file ./WEB-INF directory are not  
>> included in the
>> war file. Typically our wars contain other content in the archive root
>> folder (i.e. jsps, images, etc.). The problem is the war file  
>> gernerated out
>> of gradle just contains the WEB-INF content.
> 
> To understand: You have everything in src/webapp but only src/webapp/ 
> WEB-INF is included? That would be obviously bug. I gonna check this  
> myself today and would provide a fix ASAP.
> 
> if my war project is laid out like this:
> 
> -mywarproject
>  |
>  |-src
>    |
>    |-main
>      |
>      |-java
>      |
>      |-resources
>      |
>      |-webapp
>        |
>        |-about.jsp
>        |
>        |-WEB-INF
>          |
>          |-server-config.wsdd
> 
> the resulting war file looks like this:
> 
> -WEB-INF
>  |
>  |-about.jsp
>  |
>  |-WEB-INF
>    |
>    |-server-config.wsdd
> 
> which is not what I want, hence the included file set...
> 
>> I was trying to figure out how
>> to append filesets to the war object within the build.gradle script  
>> but
>> couldn't manage.
>>
>> The snippet:
>>
>> subprojects {
>>   usePlugin('war')
>>   dists {
>>     war() {
>>       fileSet(dir: 'src/public_html') {
>>         excludes('WEB-INF')
>>         includes('**/*')
>>       }
>>     }
>>   }
>> }
>>
>> results in the error message:
>>
>> Exception: org.gradle.api.GradleScriptException:
>> org.gradle.api.InvalidUserDataException: A task with this name already
>> exists!
>>
>> The documentation mentions examples such as
>> "myZipTask.files('path_to_file1', 'path_to_file2')" but fails to  
>> mention how
>> to get a reference to myZipTask.
>>
>> How do I access the 'war' task at runtime so that I can manipulate the
>> archive content?
> 
> usually:
> 
> mywarproject_war {
>     // configure
> }
> 
> If you don't want the project name as a default name for your archive  
> task you can set the project property: archivesBaseName (which  
> defaults to the project name)
> The basename of the task is also the default name of the actual  
> archive file. You can always change the name of the archive file with:
> 
> mywarproject_war {
>     baseName = 'othername'
> }
> 
> I'm trying to write the script in a generic way. Call me lazy. In my
> opinion writing mywarproject_war for each and every artifact is brain dead
> if you're trying to do the same thing for each and every artifact
> (absolutely criminal if you have a scriptable environment like gradle!!!).
> This is precisely the sort of declarative build that drives me away from
> ant and to some degree maven. Defining your task as a template saves
> maintainance time and and less build errors (at least they all behave
> right or wrong).
> 
>>
>> 2) The war build.gradle file contains the dependency "compile
>> project(':csl:jars:myjarproject')" which is automatically added to  
>> the war
>> lib directory. While this is sometimes desired we don't want to  
>> blow up our
>> distribution so we put the project jars in the shared classpath.  
>> How do I
>> prevent gradle from added "dependency" jars to the war lib folder?
> 
> Nice and important use case ;).
> 
> Ivy can of course handle such a situation. Our DSL on top of Ivy has  
> more constraints and is waiting for use cases to become more  
> powerful ;). I gonna provide an improvement for this during the  
> course of this day and let you know.
> 
> Looking into the gradle code I see that the "dependency" files are
> collected in the org.gradle.api.tasks.bundling.War.groovy Closure
> createAntArchiveTask(). A quick hack could be:
> 
> List files = ( libConfiguration && ( this.packageDependencies == true )) ?
> dependencyManager.resolve(libConfiguration) : []
> 
> However I don't think this is a good solution. Consider I have a war
> containing the dependency 'compile "javax.servlet:servlet-api:2.4"'.
> Although I need to library to compile I most definitely don't want to
> bundle the jar in my war lib directory because I know with 100% certainty
> that my j2ee server will provide this for me. So actually it would be
> better have something like the mavenish "<scope>provided</scope>" clause
> indicating that the dependency should not be provided by the build (i.e.
> maybe 'compile "javax.servlet:servlet-api:2.4", {[ scope : 'provided']}').
> I'm not really familiar with Ivy so I don't know if a similar construct
> exists.
> 
> I have commented your attached build script. See below.
> 
> - Hans
> 
>>
>>
>> |-csl
>> | |
>> | |-jars
>> | | |
>> | | |-myjarproject
>> | | | |
>> | | | |-src
>> | | | | |
>> | | | | |-main
>> | | | | | |
>> | | | | | |-java
>> | | | | | |
>> | | | | | |-resources
>> | | | | |
>> | | | | |-test
>> | | | |   |
>> | | | |   |-java
>> | | | |   |
>> | | | |   |-resources
>> | | | |
>> | | | |-build.gradle
>> | | |
>> | | |-build.gradle
>> | |
>> | |-wars
>> | | |
>> | | |-mywarproject
>> | | | |
>> | | | |-src
>> | | | | |
>> | | | | |-main
>> | | | | | |
>> | | | | | |-java
>> | | | | | |
>> | | | | | |-resources
>> | | | | | |
>> | | | | | |-webapp
>> | | | | |
>> | | | | |-test
>> | | | |   |
>> | | | |   |-java
>> | | | |   |
>> | | | |   |-resources
>> | | | |
>> | | | |-build.gradle
>> | | |
>> | | |-build.gradle
>> | |
>> | |-build.gradle
>> |
>> |-local_maven_repo
>> |
>> |-build.gradle
>> |
>> |-settings.gradle
>>
>> *** contents of ./setting.gradle
>>
>> include 'csl', 'csl:jars', 'csl:wars', 'csl:jars',
>>   'csl:jars:myjarproject', 'csl:wars:mywarproject'
> 
> You may skip declaring inbetween projects like csl, csl:wars and  
> csl:jars. They are included anyway.
> 
> Well there are two reasons why I did this.
> 
> 1) In the case of 'csl' (Common Service Layer) I wanted to partition the
> artifacts into groups so that I could cd to './csl' and execute 'gradle
> libs' and all the artifacts under 'csl' would be built. Without the
> settings.gradle include 'csl' I get the following error:
> 
> 14:31:52.812 [main] DEBUG o.g.initialization.SettingsProcessor - Method
> include not found in script! Delegating to settings.
> 
> Build aborted anormally because of an internal error. Run with -d option
> to get additonal debug info. Please file an issue at: www.gradle.org
> Exception is:
> java.lang.NullPointerException
>         at
> org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:177)
>         ...
> 
> 2) I don't want to maintain configuration parameters and tasks for each
> jar and war file build.gradle script (repetitive declarations is one of
> the things that I'm trying to avoid, hence the csl:jars and csl:wars
> folder and build.gradle file. This way I only need to define dependencies
> in the build artifact build.gradle files.
> 
>>
>> *** contents of ./build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
> 
> These declarations are either or. For your use case you can leave  
> this out completely.
> 
>>
>> private static final boolean javacDeprecationFlag      = false
> 
> javaDeprecationFlag = false (see Discussion in user's guide Appendix A1)
> 
>> private static final boolean javacWarningFlag          = false
>> private static final String  javacSourceCompatibility  = "1.4"
>> private static final String  javacTargetCompatibility  = "1.4"
>> private static final String  axnArchivePrefix          = "axn"
>> private static final String  axnGroup                  =  
>> "com.audatex.axn"
>> private static final String  axnVersion                = "6.2"
>>
>> allprojects {
>>   group = axnGroup
>>   version = axnVersion
>>   archivesBaseName = axnArchivePrefix + project.archivesBaseName
>>   setProperty("sourceCompatibility", javacSourceCompatibility)
> 
> sourceCompatibility = javacSourceCompatibility // does the same job
> 
>>   setProperty("targetCompatibility", javacTargetCompatibility)
>>   setProperty("compile.options.deprecation", javacDeprecationFlag)
>>   setProperty("compile.options.warnings", javacWarningFlag)
>>   dependencies {
>>     classpathResolvers.add([ name: 'local_maven_repo', url: new File(
>> rootDir, 'local_maven_repo' ).toURL().toString()])
>>     classpathResolvers.add([ name:
>> DependencyManager.DEFAULT_MAVEN_REPO_NAME, url:
>> DependencyManager.MAVEN_REPO_URL ])
>>   }
>> }
>>
>> *** contents of ./csl/build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
> 
> Can be deleted. See comment above.
> 
>>
>> subprojects {}
> 
> Of no use. Can be deleted.
> 
>>
>> *** contents of ./csl/jars/build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
> 
> Can be deleted.
> 
>>
>> subprojects {
>>   usePlugin('java')
>>   sourceCompatibility = project(':').getProperty 
>> ("sourceCompatibility")
> 
> project(':'). sourceCompatibility
> 
>>   targetCompatibility = project(':').getProperty 
>> ("targetCompatibility")
>>   compile {
>>     options.deprecation =
>> project(':').getProperty("compile.options.deprecation")
>>
> 
> project(':').compile.options.deprecation
> 
> This won't work because there are no 'jar' or 'war' tasks defined in the
> root project and hence no compile Closure exists. That's why I defined
> them as properties.
> 
>>     options.warnings    =
>> project(':').getProperty("compile.options.warnings")
>>   }
>> }
>>
>> *** contents of ./csl/wars/build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
> 
> Can be deleted.
> 
>>
>> subprojects {
>>   usePlugin('war')
>>   sourceCompatibility = project(':').getProperty 
>> ("sourceCompatibility")
>>   targetCompatibility = project(':').getProperty 
>> ("targetCompatibility")
>>   compile {
>>     options.deprecation =
>> project(':').getProperty("compile.options.deprecation")
>>     options.warnings    =
>> project(':').getProperty("compile.options.warnings")
>>   }
>>   dists {
>>     war() {
>>       fileSet(dir: 'src/public_html') {
>>         excludes('WEB-INF')
>>         includes('**/*')
>>       }
>>     }
>>   }
>> }
> 
> This creates a task with a name that already exists. See above.
> 
> This is what I was trying to do (from previous message):
> 
> subprojects {
>   usePlugin('war')
>   libs {
>     War war = task( project.name + '_war')
>     war.fileSet( dir: new File( project.srcRoot, 'main/public_html' )) {
>        exclude( 'WEB-INF' )
>        include( '**/*' )
>     }
>   }
> }
>>
>> *** contents of ./csl/jars/myjarproject/build.gradle
>>
>> type = 'jar'
> 
> Can be deleted
> 
>>
>> dependencies {
>>   compile "junit:junit:3.8.2"
>> }
>>
>> *** contents of ./csl/wars/mywarproject/build.gradle
>>
>> type = 'war'
> 
> Can be deleted
> 
>>
>> dependencies {
>>   compile project(':csl:jars:myjarproject')
>>   compile "javax.servlet:servlet-api:2.4"
>> }
>> -- 
>> View this message in context: http://www.nabble.com/War-Plugin- 
>> problems-tp18232294p18232294.html
>> Sent from the gradle-user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
> 
> --
> Hans Dockter
> Gradle Project lead
> http://www.gradle.org
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
> 
>     http://xircles.codehaus.org/manage_email
> 
> 
> 
> 

Sorry about the italics; I haven't figured out how to reply to the thread
with indentation. Thanks for the feedback...

-Dominick
-- 
View this message in context: 
http://www.nabble.com/War-Plugin-problems-tp18232294p18260164.html
Sent from the gradle-user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to