简体   繁体   English

如何将Artifactory WAR添加为Gradle依赖项

[英]How to add an Artifactory WAR as a Gradle dependency

I'm working on a Spring MVC project (using Gradle) to produce a template to be integrated on different projects. 我正在一个Spring MVC项目(使用Gradle)中工作,以产生一个要集成到不同项目中的模板。 The template project contains few HTML files and some classes to handle the properties. 模板项目包含少量HTML文件和一些用于处理属性的类。 I've configured the artifactory-gradle-plugin to generate and publish a WAR containing my HTML files and classes. 我已经配置了artifactory-gradle-plugin来生成和发布包含我的HTML文件和类的WAR。 Everything works just fine and my WAR and POM files are now available under my Artifactory server. 一切正常,并且我的WAR和POM文件现在在Artifactory服务器下可用。 Here's a part of my build.gradle file 这是我的build.gradle文件的一部分

war {
    rootSpec.exclude('**/*.properties')
    [...]
    rootSpec.exclude('**/test/**')
    rootSpec.exclude('**/*.jar')
}

artifactory {
    publish {
        contextUrl = "myurl"  
        repository {
            repoKey = 'myrepo'
            username = "myuser"
            password = "mypasswd"
            maven = true
        }
        defaults {
            publications ('mavenJava')
        }
    }
}
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.web
        }
    }
 }    

Unfortunately when I try to add this artifact as dependency on an other project, Gradle successfully finds the WAR but nothing is integrated in the project. 不幸的是,当我尝试将此工件添加为对其他项目的依赖时,Gradle成功地找到了WAR,但项目中没有任何集成。 I can't find any HTML, classes or war files in the project. 我在项目中找不到任何HTML,类或war文件。

dependencies {
    compile(group: 'test.spring', name: 'test-layout', version: '0.0.1', ext: 'war')
}

Is there something missing or am I completely of the track with this? 是否缺少某些东西,或者我是否完全了解这一点?

It does not make sense to add dependency to a war file since that is a packaging for an application server and not for other projects. 向war文件添加依赖项没有任何意义,因为这是应用程序服务器而不是其他项目的包装。

I suggest you also publish other artifacts from your original project, and instead import them as dependencies. 我建议您还从原始项目中发布其他工件,而是将其作为依赖项导入。

An alternative would be to unpack the war in a separate task but that is not needed when you have control over the source project. 另一种选择是将战争打包成一个单独的任务,但是当您控制源项目时就不需要。

OK, after asking the same question on the Gradle forum, it seems that there is no easy way to achieve this using one single artifact without loosing all dependencies (special thanks to Lance_Java). 好吧,在Gradle论坛上问了同样的问题之后,似乎没有一种简单的方法可以使用一个工件来实现这一目标,同时又不失去所有依赖关系(特别感谢Lance_Java)。 It sounds like I have to create a JAR and a ZIP artifact (see the zip references as described in the previous @Joachim Nilsson post) 听起来我必须创建一个JAR和一个ZIP工件(请参阅前面的@Joachim Nilsson帖子中描述的zip参考)

https://discuss.gradle.org/t/how-to-add-an-artifactory-war-as-a-gradle-dependency/19804/4 https://discuss.gradle.org/t/how-to-add-an-artifactory-war-as-a-gradle-dependency/19804/4

My final solution will be to simply deploy my templates under a "commons" web repository and deploy my configuration classes in a JAR artifact. 我的最终解决方案是将模板简单地部署在“公共” Web存储库下,并将配置类部署在JAR工件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM