3

1 つのメイン プロジェクトと 2 つのサブプロジェクトがあります。サブプロジェクトの 1 つは、「独自の」ビルド構造を持つ playframework です。他のすべてのプロジェクトがソースディレクトリ src/main/java などの標準レイアウトを使用するように、その 1 つのサブプロジェクトに対してのみソースディレクトリをオーバーライドするにはどうすればよいですか?

機能しない最初の回答とディレクトリ構造を試しました

 stserver
     build.gradle (1)
     project1
     webserver
         build.gradle (2)

2nd gradleファイルはこちら

sourceSets.main{
  java.srcDirs = ['app']
}

task build << {
  println "source sets=$sourceSets.main.java.srcDirs"
}

これを実行すると、stserver/webserver/app???? ではなく stserver/app が srcDir として出力されます。ここで何が間違っていますか?

ありがとう、ディーン

4

1 に答える 1

2

ピーターが提案したドキュメントをご覧ください。私は Play Framework 2.0~ で作業する準備ができbuild.gradleているので、ここで共有して、役立つセットアップのヒントを見つけていただければ幸いです。

私のプロジェクト構造:

+- master/
  +- build.gradle  <-- contains common setup, 
                       and applies 'java' plugin to all subprojects
+- ui/             <-- project using Play framework
  +- build.gradle  <-- excerpt from this file is posted below

からの抜粋build.gradle

repositories{
  maven{
    //Play dependencies will be downloaded from here
    url " http://repo.typesafe.com/typesafe/releases"
  }
}

//Optional but useful. Finds 'play' executable from user's PATH
def findPlay20(){
  def pathEnvName = ['PATH', 'Path'].find{ System.getenv()[it] != null }
  for(path in System.getenv()[pathEnvName].split(File.pathSeparator)){
    for(playExec in ['play.bat', 'play', 'play.sh']){
      if(new File(path, playExec).exists()){
        project.ext.playHome = path
        project.ext.playExec = new File(path, playExec)
        return
      }
    }
  }
  throw new RuntimeException("""'play' command was not found in PATH.
Make sure you have Play Framework 2.0 installed and in your path""")
}

findPlay20()

configurations{
  //Configuration to hold all Play dependencies
  providedPlay
}

dependencies{
  providedPlay "play:play_2.9.1:2.0+"
  //Eclipse cannot compile Play template, so you have to tell it to
  //look for play-compiled classes
  providedPlay files('target/scala-2.9.1/classes_managed')

  //other dependencies
}

sourceSets.main{
  java.srcDirs = ['app', 'target/scala-2.9.1/src_managed/main']
  //Make sure Play libraries are visible during compilation
  compileClasspath += configurations.providedPlay
}

//This task will copy your project dependencies (if any) to 'lib'
//folder, which Play automatically includes in its compilation classpath
task copyPlayLibs(type: Copy){
  doFirst { delete 'lib' }
  from configurations.compile
  into 'lib'
}

//Sets up common play tasks to be accessible from gradle.
//Can be useful if you use gradle in a continuous integration 
//environment like Jenkins.
//
//'play compile' becomes 'gradle playCompile'
//'play run' becomes 'gradle playRun', and so on.
[ ['run',     [copyPlayLibs]],
  ['compile', [copyPlayLibs]],
  ['clean',   []],
  ['test',    []],
  ['doc',     [copyPlayLibs]],
  ['stage',   [copyPlayLibs]] ].each { cmdSpec ->
    def playCommand = cmdSpec[0]
    def depTasks = cmdSpec[1]
    task "play${playCommand.capitalize()}" (type: Exec,
                                            dependsOn: depTasks,
                                            description: "Execute 'play ${playCommand}'") {
     commandLine playExec, playCommand
    }
}

//Interate playClean and playCompile task into standard
//gradle build cycle
clean.dependsOn "playClean"
[compileScala, compileJava]*.dependsOn "playCompile"

//Include Play libraries in Eclipse classpath
eclipse {
  classpath {
    plusConfigurations += configurations.providedPlay
  }
}

注:既存のより大きなgradleファイルから上記を抽出したばかりなので、いくつか不足している可能性があるため、保証はありません:) とにかく役立つことを願っています. 幸運を。

于 2012-06-21T04:08:03.737 に答える