0

I'm trying to build a kind of template build script for my java web projects. This template is stored in my apache web server. To use it in a project, I use apply from 'http://myserver/templateWarScript.gradle'. The configuration for the final war is done in this template.

For all of my java web projects, I need to put the content of a zip file (containing JavaScript files, images, etc) into the final war file. To share this zip file, I put it in my local repository.

Now, I'm trying to find a way to include its content in my final war. But I can't found a way to do it. I'm trying to put the following line in my template script:

  configurations {
        zipWebResource
  }

   dependencies {
        zipWebResource group: 'utilities.template', name: 'webResource', version: '1.0', ext: 'zip'
   }

  //test task 
  task testZipPath << {
        println "zip path:" + configurations.zipWebResource.asPath
   }
   //

   //my war configuration
   war {
        println "zip path:" + configurations.zipWebResource.asPath
    }

If I put the 'configurations.zipWebResource.asPath' in the war configuration, I've got an error which shows that gradle can't find the zip dependency.
But, if I remove it from the war configuration, I can read it by my test task.

I've also try to read it in a method or directly in the gradle script, but I've got the same error. After reading the gradle user guide, I think that my problem is linked with the configuration or/and the execution phase.

I would like to understand why I can read the configurations.zipWebResource.asPath in a task but not in a configuration. My goal is to use the zip like a dependency and put it's content in the root of the generated war

Many Thanks.

4

1 回答 1

0

apply from:将此片段包含在 中,并将其直接粘贴到构建脚本中(替换)之间没有语义差异apply from:。也许您更改了声明的顺序,或者在其中一种情况下本地存储库中没有 zip。

编辑以反映您的新问题:通常,不应在配置时解决配置,而应仅在执行时解决。在您的情况下,asPath将触发解决方案。对于外部依赖,它应该可以工作(但不建议这样做,因为它可能会减慢您的构建速度)。问题可能出在其他地方(例如错误的声明顺序)。

PS:如果没有明确的问题,Stack Overflow 不是这种支持的好格式。获得 Gradle 支持的最佳地点是:http ://forums.gradle.org

于 2013-06-04T09:33:34.043 回答