简体   繁体   English

gradle:compilePlayBinaryPlayRoutes不生成所有导入

[英]gradle :compilePlayBinaryPlayRoutes is not generating all imports

I am switching a play app from SBT to gradle and the routes and reverse routes scala files are not being generated with 我正在将播放应用程序从SBT切换到gradle,并且没有生成路由和反向路由scala文件

import _root_.play.libs.F

which is causing 这是造成的

build/src/play/binary/routesScalaSources/controllers/ReverseRoutes.scala:260: not found: value F
def validate(accountId:F.Option[java.lang.Long]): Call = {

I am using gradle 3.5, play: '2.4.8', scala: '2.11' and java: '1.8'. 我正在使用gradle 3.5,播放:'2.4.8',scala:'2.11'和java:'1.8'。 Does anyone know if there is a compatibility issue with or some other known issue that is stopping the import from being added to the generated scala file? 有没有人知道是否存在兼容性问题或某些其他已知问题阻止导入被添加到生成的scala文件中?

** EDIT ** **编辑**

I found this class RoutesCompile with a method additionalImports but I can't find how to use it in the build.gradle file. 我发现这个类RoutesCompile有一个方法additionalImports但我找不到如何在build.gradle文件中使用它。 (I am super new to gradle, more of a maven guy) (我是gradle的新手,更像是一个maven家伙)

** EDIT 2 ** **编辑2 **

Based on the Javadoc in the RoutesCompile class it seems like I should be adding it to the model like this: 基于RoutesCompile类中的Javadoc,我似乎应该将它添加到模型中,如下所示:

model {
  components {
    play {
        platform play: '2.4.8', scala: '2.11', java: '1.8'
        injectedRoutesGenerator = true
        additionalImports = ['play.libs.F']
        sources {
            twirlTemplates {
                defaultImports = TwirlImports.JAVA
                source.srcDir "assets/views"
                source.exclude "assets/stylesheets"
            }
        }
     }
   }
}

But I get the following error: 但是我收到以下错误:

> Exception thrown while executing model rule: play { ... } @ build.gradle line 147, column 9
> No such property: additionalImports for class: org.gradle.play.PlayApplicationSpec

I have finally found the answer to my issue. 我终于找到了问题的答案。 I needed to get the task and add the additional import that way. 我需要获取任务并以这种方式添加额外的导入。

model {
components {
    play {
        platform play: '2.4.8', scala: '2.11', java: '1.8'
        injectedRoutesGenerator = true
        tasks.withType(RoutesCompile) {
            additionalImports = ['play.libs.F']
        }

        sources {
            twirlTemplates {
                defaultImports = TwirlImports.JAVA
                source.srcDir "assets/views"
                source.exclude "assets/stylesheets"
            }
        }
     }
  }
}

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

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