简体   繁体   中英

Gradle generated Jar does not include gwt.xml file?

I created a small library project with the following 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.

How can I force gradle to include the sources and the gwt.xml file in the generated jar?

Here is the solution to include the *.java files use:

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

The include any other resources like gwt.xml files put them into:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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