在使用特定于jar的任务编写build.gradle时遇到问题

时间:2016-08-30 14:47:15

标签: java gradle build.gradle

我的目录和文件名为src / main / java / HelloWorld / HelloWorld.java。我的build.gradle有:

sourceSets {
  main {
    java {
      srcDir 'src'
    }
  }
}

task worldJar(type: Jar) {
  baseName = "WorldJar"

  from(sourceSets.main.output) {
    include "HelloWorld/**"
  }
}

但是,生成的jar中没有HelloWorld.class。知道我做错了吗?

1 个答案:

答案 0 :(得分:0)

您必须创建单独的包并执行此操作:

sourceSets {
  main {
    java {
      srcDir 'src'
    }
  }
}

task worldJar(type: Jar) {
  baseName = "WorldJar"

  println sourceSets.main.output
  from(sourceSets.main.output) {
    include "HelloWorld/**"
  }
}

task spencerJar(type: Jar) {
  baseName = "SpencerJar"

  from(sourceSets.main.output) {
    include "HelloSpencer/**"
  }
}