War Plugin problems

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

War Plugin problems

Dominick More
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. 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?

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?


|-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'

*** contents of ./build.gradle

childrenDependOnMe()
dependsOnChildren()

private static final boolean javacDeprecationFlag      = false
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)
  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()

subprojects {}

*** contents of ./csl/jars/build.gradle

childrenDependOnMe()
dependsOnChildren()

subprojects {
  usePlugin('java')
  sourceCompatibility = project(':').getProperty("sourceCompatibility")
  targetCompatibility = project(':').getProperty("targetCompatibility")
  compile {
    options.deprecation = project(':').getProperty("compile.options.deprecation")
    options.warnings    = project(':').getProperty("compile.options.warnings")
  }
}

*** contents of ./csl/wars/build.gradle

childrenDependOnMe()
dependsOnChildren()

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('**/*')
      }
    }
  }
}

*** contents of ./csl/jars/myjarproject/build.gradle

type = 'jar'

dependencies {
  compile "junit:junit:3.8.2"
}

*** contents of ./csl/wars/mywarproject/build.gradle

type = 'war'

dependencies {
  compile project(':csl:jars:myjarproject')
  compile "javax.servlet:servlet-api:2.4"
}
Reply | Threaded
Open this post in threaded view
|

Re: War Plugin problems

hans_d
Administrator

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.

> 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'
}

>
> 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.

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.

>
> *** 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

>     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.

>
> *** 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


Reply | Threaded
Open this post in threaded view
|

Re: War Plugin problems

Dominick More
In reply to this post by Dominick More
Thanks Jerod Lass for the tip about accessing the war task!!! At least I was able to figure out how to include the public_html files. This sort of thing should definitely be documented more clearly.

*** updated contents of ./csl/wars/build.gradle

dependsOnChildren()

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")
  }
  libs {
    War war = project.task( project.name + '_war')
    war.fileSet( dir: new File( project.srcRoot, 'main/public_html' )) {
      exclude( 'WEB-INF' )
      include( '**/*' )
    }
  }
}

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. 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?

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?


|-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'

*** contents of ./build.gradle

childrenDependOnMe()
dependsOnChildren()

private static final boolean javacDeprecationFlag      = false
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)
  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()

subprojects {}

*** contents of ./csl/jars/build.gradle

childrenDependOnMe()
dependsOnChildren()

subprojects {
  usePlugin('java')
  sourceCompatibility = project(':').getProperty("sourceCompatibility")
  targetCompatibility = project(':').getProperty("targetCompatibility")
  compile {
    options.deprecation = project(':').getProperty("compile.options.deprecation")
    options.warnings    = project(':').getProperty("compile.options.warnings")
  }
}

*** contents of ./csl/wars/build.gradle

childrenDependOnMe()
dependsOnChildren()

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('**/*')
      }
    }
  }
}

*** contents of ./csl/jars/myjarproject/build.gradle

type = 'jar'

dependencies {
  compile "junit:junit:3.8.2"
}

*** contents of ./csl/wars/mywarproject/build.gradle

type = 'war'

dependencies {
  compile project(':csl:jars:myjarproject')
  compile "javax.servlet:servlet-api:2.4"
}
Reply | Threaded
Open this post in threaded view
|

Re: War Plugin problems

hans_d
Administrator

On Jul 3, 2008, at 11:44 AM, Dominick More wrote:

>
> Thanks Jerod Lass for the tip about accessing the war task!!! At  
> least I was
> able to figure out how to include the public_html files. This sort  
> of thing
> should definitely be documented more clearly.

I agree. We spend a lot of resources into our documentation though.  
But as a Gradle developer knowing the internals one is partially  
blind to what needs a better explanation. We depend on user feedback  
like yours for this.

>
> *** updated contents of ./csl/wars/build.gradle
>
> dependsOnChildren()

You can leave dependsOnChildren out as well.

- Hans

>
> subprojects {
>   usePlugin('war')
>   sourceCompatibility = project(':').getProperty
> ("sourceCompatibility")

As said in the earlier email:

sourceCompatibility = project(':').sourceCompatibility

might be nicer to read.

>   targetCompatibility = project(':').getProperty
> ("targetCompatibility")
>   compile {
>     options.deprecation =
> project(':').getProperty("compile.options.deprecation")
>     options.warnings    =
> project(':').getProperty("compile.options.warnings")
>   }
>   libs {
>     War war = project.task( project.name + '_war')

The project property is appended by default. So you can leave it out.

War war = task( project.name + '_war')

>     war.fileSet( dir: new File( project.srcRoot, 'main/
> public_html' )) {
>       exclude( 'WEB-INF' )
>       include( '**/*' )
>     }
>   }
> }
>

I'm curios. Why don't you put the content of public_html in the src/
webapp folder?

- Hans

>
> 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. 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?
>>
>> 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?
>>
>>
>> |-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'
>>
>> *** contents of ./build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
>>
>> private static final boolean javacDeprecationFlag      = false
>> 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)
>>   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()
>>
>> subprojects {}
>>
>> *** contents of ./csl/jars/build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
>>
>> subprojects {
>>   usePlugin('java')
>>   sourceCompatibility = project(':').getProperty
>> ("sourceCompatibility")
>>   targetCompatibility = project(':').getProperty
>> ("targetCompatibility")
>>   compile {
>>     options.deprecation =
>> project(':').getProperty("compile.options.deprecation")
>>     options.warnings    =
>> project(':').getProperty("compile.options.warnings")
>>   }
>> }
>>
>> *** contents of ./csl/wars/build.gradle
>>
>> childrenDependOnMe()
>> dependsOnChildren()
>>
>> 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('**/*')
>>       }
>>     }
>>   }
>> }
>>
>> *** contents of ./csl/jars/myjarproject/build.gradle
>>
>> type = 'jar'
>>
>> dependencies {
>>   compile "junit:junit:3.8.2"
>> }
>>
>> *** contents of ./csl/wars/mywarproject/build.gradle
>>
>> type = 'war'
>>
>> 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-tp18232294p18255648.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


Reply | Threaded
Open this post in threaded view
|

Re: War Plugin problems

Dominick More
In reply to this post by hans_d
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.

Dominick More wrote
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'
}

Dominick More wrote
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.

Dominick More wrote
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.

Dominick More wrote
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

Dominick More wrote
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.

Dominick More wrote
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
Reply | Threaded
Open this post in threaded view
|

RE: War Plugin problems

Detering Dirk-2
Hello Dominick,

> -----Original Message-----
> From: Dominick More [mailto:[hidden email]]
> Sent: Thursday, July 03, 2008 4:34 PM
> To: [hidden email]
> Subject: Re: [gradle-user] War Plugin problems


Please, please, do *NOT* quote 428 lines of mail
thread to put only something like "thanks for the feedback"
into line 430+ .

(See: http://www.netmeister.org/news/learn2quote2.html 
and http://www.ietf.org/rfc/rfc1855.txt )

KR
Det


***********************************************************************

Die Information in dieser email ist vertraulich und ist ausschliesslich
fuer den/die benannten Adressaten bestimmt. Ein Zugriff auf diese
email durch andere Personen als den/die benannten Adressaten ist
nicht gestattet. Sollten Sie nicht der benannte Adressat sein, loeschen
Sie bitte diese email.

***********************************************************************

BITMARCK Software GmbH
Paul-Klinger-Strasse 15, 45127 Essen
 
Amtsgericht Essen HRB 20680
Geschaeftsfuehrer: Frank Krause, Andreas Prenneis


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: War Plugin problems

hans_d
Administrator
In reply to this post by Dominick More
Hi Dominick,

just a short status update. I have posted a sample project to the war  
thread Jerod has started.

Unfortunately I had no time yet to add the feature to leave out  
dependencies in a war. I will implement this soon. You might want to  
follow the issue via: http://jira.codehaus.org/browse/GRADLE-140

- Hans

--
Hans Dockter
Gradle Project lead
http://www.gradle.org





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

    http://xircles.codehaus.org/manage_email