简体   繁体   English

Gradle生成的Jar是否不包含gwt.xml文件?

[英]Gradle generated Jar does not include gwt.xml file?

I created a small library project with the following build.gradle: 我使用以下build.gradle创建了一个小型图书馆项目:

apply plugin: 'java'
apply plugin: 'gwt-base'
apply plugin: 'eclipse'

buildscript {
  repositories {
    mavenCentral()
    jcenter()
    maven {
        url new File(rootProject.projectDir.parentFile, 'repo').toURI()
    //  url "https://oss.sonatype.org/content/repositories/snapshots/"
    }
  }
  dependencies {
    classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.6'
  }
}

gwt {
    gwtVersion='2.7.0'
}

The folder structure looks like this: 文件夹结构如下所示:

/library
/library/Library.gwt.xml
/library/client/HelloWorldWidget.java

The sources are taken from here . 资料来自这里

When I perform a gradle build gradle generates a jar file which does not contain the sources and also does not contain the gwt.xml module file. 当我执行gradle build gradle会生成一个jar文件,该jar文件不包含源文件,也不包含gwt.xml模块文件。

How can I force gradle to include the sources and the gwt.xml file in the generated jar? 如何强制gradle在生成的jar中包含源代码和gwt.xml文件?

Here is the solution to include the *.java files use: 这是包含*.java文件使用的解决方案:

jar {
  from('src/main/java') {
    include '**/*.java'
  }
}

The include any other resources like gwt.xml files put them into: 包括gwt.xml文件之类的任何其他资源gwt.xml将它们放入:

/src/main/resources

Alternatively you can use: 或者,您可以使用:

jar {
  from project.sourceSets.main.allSource
  from project.sourceSets.main.output
}

When using the Java plugin, Gradle assumes that the project has the standard structure , ie 'src\\main\\java' & 'src\\test\\java'. 使用Java插件时,Gradle假定项目具有标准结构 ,即'src \\ main \\ java'和'src \\ test \\ java'。 Therefore when executing the build tasks it simply doesn't find any of those directories. 因此,在执行构建任务时,它根本找不到任何这些目录。

The best way to fix this will be to define your project structure by modifying the existing source sets, which define where your sources are: 解决此问题的最佳方法是通过修改现有的源集来定义项目结构,这些源集定义了源代码的位置:

sourceSets {
    main {
        java {
            include '/library/**'
        }
    }
    test {
        java {
            include '/test/sources/directory/**'
        }
    }
}

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

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