Sporadic compile errors in scala.html compilations because routes are not compiled yet

I’m working on a rather large project and recently we have been getting more an more builds on the build server failing due to what seems to be a race condition between generating the routes files and compiling them and compiling the scala.html files. We get errors like the following

[info] Compiling 752 Scala sources and 2695 Java sources to /home/********/target/classes...
[error] /home/********/app/views/bookingarea/main.scala.html:14: value Application is not a member of object controllers.extranet.routes
[error]         <script src="@controllers.extranet.routes.Application.javascriptRoutes" type="text/javascript" ></script>
[error]                                                   ^
[error] /home/********/app/views/extranet/accommodations/accommodation.scala.html:23: value Products is not a member of object controllers.extranet.routes
[error]                 url: '@controllers.extranet.routes.Products.listSlugs(controllers.extranet.ProductCategoryW.forProduct(accommodation), accommodation.getId())',
[error]                                                    ^

The exact same code will then successfully build in a second attempt.

Is there a way to ensure the routes have been generated before the twirl templates are compiled?

I figured this out myself. There are more than one .routes files in the project and one of them extranet.routes was referencing most of the controllers in the controllers.extranet package but another route file was referencing just one of the classes there.

This would result in that file sometimes overwriting the routes.java file in the controllers.extranet package. The endpoints in the smaller file are never routed to, meaning if that file looses no errors occur.

The fix was to move the class referred to in a separate routes file to a separate package.

1 Like