-
Notifications
You must be signed in to change notification settings - Fork 41
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
Implement support for WebJars and LESS as assets pipeline #132
Conversation
d840c1d
to
ecb94d5
Compare
This is an impressive bit of work. Thanks for your contribution! |
Looks like the docs test are failing, which is abnormal as they aren't failing on master. Could you take a look and let me know why? |
ecb94d5
to
cba5cb5
Compare
@JLLeitschuh Oops. I forgot to add declare the new But now somehow it does not trigger Travis build now 😅 what is going on? |
@JLLeitschuh the CI test has run now. Doc test is green :) |
Before merging this, I'd like to see master fixed. See #136 |
cba5cb5
to
554c8b4
Compare
554c8b4
to
fe8c126
Compare
@JLLeitschuh I've rebased to latest master, now everything is green, could you take a look again? |
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.
Looks good so far! A few changes I'd appreciate. I'm trying to get someone else to take a look as well.
src/integTest/groovy/org/gradle/playframework/tasks/AbstractAssetsTaskIntegrationTest.groovy
Outdated
Show resolved
Hide resolved
project.getTasks().named(PLAY_RUN_TASK_NAME, PlayRun.class, task -> { | ||
task.getAssetsDirs().from(webJarsExtractTaskProvider.get().getOutputDirectory()); | ||
}); | ||
project.getTasks().matching(task -> task.getName().equals(LESS_COMPILE_TASK_NAME)).forEach(task -> { |
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 forces the realization of all tasks. Can you use a type constraint instead of a name constraint?
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.
Ah, just realized this. Changed this to:
Optional.ofNullable(project.getTasks().findByName(LESS_COMPILE_TASK_NAME)).ifPresent(task -> {
Can't find any method which accepts type constraint but does not fail if the task is not found :(
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.
Asking internally about this. I think that findByName
is still forcing some task configuration & realization?
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.
To be honest, I'm not really sure about this. The thing is I cannot use .named()
because it will throw if the less plugin is not applied. Most of the methods I found is doing the similar thing (throwing when task is not found).
Could you advise the correct method? I could not find anything by browsing the Task javadoc / documentation :(
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.
After asking internally, the answer I got was tasks.matching { ... }.configureEach { ... }
This may be what you already had (sorry). But supposedly, this is what you want to use here.
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 see. No worries, I added it back!
src/main/java/org/gradle/playframework/tasks/WebJarsExtract.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gradle/playframework/tools/internal/less/Less4jCompiler.java
Outdated
Show resolved
Hide resolved
src/main/java/org/gradle/playframework/tools/internal/webjars/WebJarsExtractor.java
Outdated
Show resolved
Hide resolved
fe8c126
to
c51cf14
Compare
@JLLeitschuh Thanks for reviewing; I have addressed/answered all your comments. |
* } | ||
* </pre> | ||
*/ | ||
public interface LessSourceSet { |
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.
Out of curiosity, does this become accessible via the Kotlin DSL as well?
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.
Honestly I am not using Kotlin DSL so I cannot verify. But I believe it should because it follows exactly the same pattern as the other source sets in the existing codebase.
return lessCompilerClasspath; | ||
} | ||
|
||
public List<File> getIncludePaths() { |
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.
Is this an input or an output?
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.
Ah, interesting, this could be @InputFiles
. Added!
return outputDirectory; | ||
} | ||
|
||
@Classpath |
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 infer an input/output or does it need to be explicit?
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 I was just following existing JavaScriptMinify
task here: https://github.com/gradle/playframework/blob/master/src/main/java/org/gradle/playframework/tasks/JavaScriptMinify.java#L67
But it seems that according to the docs here: https://docs.gradle.org/current/userguide/more_about_tasks.html I should also add @InputFiles
to be compatible with some older Gradle versions, which I do not actually use. Should I still add it?
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 know I continue to be nitpicky. This is just a large change. This should hopefully be the last review pass I need to take on this.
@fushar are you willing to own this change a bit after it is merged and help manage issues/bugs that are associated with it moving forward? |
c51cf14
to
0bf3a23
Compare
Sure, I am still maintaining a project which heavily relies on these plugins, so I should be able to help on that. |
Thanks @fushar! We just did a release, we're going to try to get this into the next one, hopefully later today, or tomorrow. |
00b3a64
to
2b905a2
Compare
Signed-off-by: Ashar Fuadi <[email protected]>
2b905a2
to
2edfc45
Compare
Hey @fushar, Really sorry. I went on vacation the past two weeks and thought that someone would follow up here. I had a discussion with @big-guy about this. We were wondering why the webjar component needed to be a part of this plugin and couldn't be a wholly-separate community maintained plugin? It doesn't seem like it's play specific. |
Hi @JLLeitschuh sorry for late reply; was busy with work. I was just trying to get feature parity with the original SBT plugin counterpart. As per the original docs, WebJars is a built-in feature, thus this PR. I actually had tried writing 2 separate plugins for WebJars and LESS, based on the deprecated Gradle Software Model. However, the LESS plugins actually depends on WebJars output. That's also another reason why I put those two together in the same codebase. What do you think? Should I still somehow separate those two? |
@fushar I think that your rationale for why you're including it makes sense. Let me take another pass quickly. |
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.
Thanks @JLLeitschuh, appreciate it 😄 |
project.getTasks().matching(task -> task.getName().equals(LESS_COMPILE_TASK_NAME)).configureEach(task -> { | ||
LessCompile lessCompileTask = (LessCompile) task; | ||
lessCompileTask.dependsOn(webJarsExtractTaskProvider); | ||
lessCompileTask.getIncludePaths().add(webJarsExtractTaskProvider.get().getOutputDirectory().get().getAsFile()); | ||
}); |
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.
Instead of doing this, can you use named
inside of a check to make sure that the less compile plugin is applied?
Hey @fushar, So, after a long conversation with @big-guy we decided that we unfortunately don't want to include these plugins to this repo. However, we are more than willing to add tests to this repository to verify that an external plugin stays compatible with a plugin that adds this functionality and would be happy to link to an external plugin from our documentation. As a part of this, this will give you the freedom to use some of the newer APIs and will keep that external plugin from being constrained to the same Gradle version support as this one. Of note, some of the patterns and paradigms you mimicked from other code in this plugin was a carryover from the original port and extraction of this code from Gradle/Gradle. That extraction maintained some of the less-than-optimal patterns of the Gradle Software Model that is now deprecated. As a standalone plugin you can more easily adopt some of the newer provider based APIs that automatically track task dependencies without requiring the use of We want to thank you for your contribution, and we hope you will contribute more to this plugin in the future. |
Hi @JLLeitschuh & @big-guy, Ah... I see. Understandable. Though most probably I don't really have the bandwidth in the near future to pick this up (make separate plugins, re-testing, rewriting the docs changes etc). So for now I'll close this PR and live with my own fork for the time being. Hopefully i can revisit this some time next year. Thanks for your time reviewing this PR! 🙂 |
Full support for WebJars as described here: https://www.playframework.com/documentation/2.8.x/AssetsOverview#WebJars
Add plugin
org.gradle.playframework-webjars
Add
webJar
configuration for adding dependency to WebJar libraries, e.g.Extracted jars are under
lib/
in the assets jarImplementation: https://github.com/webjars/webjars-locator-core
Full support for LESS as described here:
https://www.playframework.com/documentation/2.8.x/AssetsLess
org.gradle.playframework-less
less
source set_*.less
)lib/
generated by WebJars aboveInclude the following to the
runPlay
's assets dirs so that the compiled/generated assets can be served during development mode:Add integration tests
Add asset pipelines docs