New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create minimal sbt plugin for Play services #8011
Conversation
3c3b67d
to
0b44a09
Compare
) | ||
override def projectSettings = PlaySettings.defaultSettings ++ Seq( | ||
scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "utf8"), | ||
javacOptions in Compile ++= Seq("-encoding", "utf8", "-g") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this change, but perhaps we could make these values overridable by users instead of hardcoded.
E.g.
playScalacOptions := Seq("-deprecation", "-unchecked", "-encoding", "utf8")
scalacOptions ++= playScalacOptions
* | ||
* Declares common settings for both Java and Scala based web projects, as well as sbt-web and assets settings. | ||
*/ | ||
object PlayWeb extends AutoPlugin { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this provide the same behaviour as the old Play
plugin? What's the impact of changing the name to PlayWeb
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gmethvin has told me on another channel that most people will be using the PlayJava
and PlayScala
plugins, not the Play
plugin.
@@ -79,7 +95,7 @@ object PlayScala extends AutoPlugin { | |||
* This plugin enables the Play netty http server | |||
*/ | |||
object PlayNettyServer extends AutoPlugin { | |||
override def requires = Play | |||
override def requires = PlayService |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
/** | ||
* Play layout plugin to switch to the classic Play layout instead of the standard Maven layout. | ||
* | ||
* This is enabled automatically with the PlayWeb plugin but not with the PlayService plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment reads to me like PlayWeb
depends on PlayLayoutPlugin
, but the requres = PlayWeb
below seems to show that PlayLayoutPlugin
depends on PlayWeb
. Or am I just confused? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's an AutoPlugin
, whose trigger is allDependencies
. So it's automatically applied when all dependencies are satisfied. Perhaps it would be better to just make it a dependency of PlayWeb
, but I was just going along with the way it was already done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it probably would make more sense for it to be a dependency of PlayWeb
. That also means you could apply it to a non-Play project which would make sense.
val ReadTimeout = 10000 | ||
|
||
@tailrec | ||
def verifyResourceContains(path: String, status: Int, assertions: Seq[String], attempts: Int): Unit = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really part of this PR, but it feels like this common code should be in a library somewhere…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1.
This could be side by side with MediatorWorkaroundPlugin
.
9e6a48a
to
2380783
Compare
@@ -16,7 +16,7 @@ import sbt._ | |||
* }}} | |||
*/ | |||
object PlayFilters extends AutoPlugin { | |||
override def requires = Play | |||
override def requires = PlayWeb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand we need to do this so that we can have better compatibility but to me, this plugin (and also PlayAkkaHttpServer
and PlayNettyServer
) should just add some settings and requires
only sbt.plugins.JvmPlugin
. Moreover, I expect people to be doing something like .enablePlugins(PlayScala).enablePlugins(PlayFilters)
instead of just doing enablePlugins(PlayFilters)
so that they will get PlayWeb
through PlayScala
or PlayJava
.
Is there any reason these plugins needs PlayWeb
or PlayService
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same for PlayLogback
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependency is there because this is an AutoPlugin
that's triggered on AllRequirements
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we should have it added by default for PlayWeb
though, to provide the secure-by-default experience. I guess that's sort of the point of this plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do think we should have it added by default for PlayWeb though, to provide the secure-by-default experience. I guess that's sort of the point of this plugin.
I like that we do this by using a plugin:
- It is enabled by default (since it is an
AutoPlugin
) - Being a plugin make it easy to disable it if necessary.
My main point here is that if it needs to requires
PlayWeb
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the filters are designed to help with web-oriented issues, or at least things that generally affect public-facing apps. With a service you don't often need those things, and I think PlayService
should by default give you a minimal service.
The only point of requires = PlayWeb
is for the AllRequirements
trigger.
# Build the distribution and ensure that the files we expect are indeed there | ||
> stage | ||
$ exists target/universal/stage/README | ||
$ exists target/universal/stage/bin/root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should test routes generation too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe you can run
and have a task to make a request to /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, you already have verifyResourceContains
. It just needs to be added to the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a second thought, and based on the basic-service
tests, it could be good to check for the generated/compiled route files. That is because we can have routers without the router compiler (like in basic-service
).
# Build the distribution and ensure that the files we expect are indeed there | ||
> stage | ||
$ exists target/universal/stage/README | ||
$ exists target/universal/stage/bin/root |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs tests to add verifyResourceContains
test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the verifyResourceContains
test.
7d057f6
to
5d8dda6
Compare
|
||
> run | ||
|
||
> verifyResourceContains / 200 Hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing playStop
as the last line.
7250d1d
to
a6da4d4
Compare
I think this is good to merge. I'd like to add some examples as well, so I'll do that and then update the documentation in another PR. |
Fantastic, thanks for getting this in place @gmethvin Looking forward to working with a leaner version of Play 😄 |
a6da4d4
to
1067236
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
@gmethvin we can add Highlights27 for this change.
Fixes #7991.
Splits the current
Play
plugin into aPlayService
andPlayWeb
plugin.PlayService
uses the standard maven layout and doesn't automatically add template support, sbt-web, or routes file support. Support for routes can be easily added using theRoutesCompiler
sbt plugin. The old Play layout can be added by addingPlayLayoutPlugin
.Eventually the
PlayService
plugin could also be the base plugin for Lagom services.