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
PT-391: [NNP] Support java only modules #256
Conversation
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. It would be good for @devisnik to scan this too.
classesTask.mustRunAfter task | ||
|
||
JavaCompile compileTask = | ||
(JavaCompile) project.tasks.getByName("compile${taskName.capitalize()}Java") |
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.
why this is on a separate line? it doesn't look like too long
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.
setValue(null); | ||
} | ||
|
||
// this should result in a warning in the IDEA |
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 the right place for this comment? shouldn't be on line 6 instead?
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.
so true :)
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.
Some suggestions.
Apart from that, LGTM.
@@ -14,3 +14,4 @@ TODO | |||
|
|||
The plugin is **under early development** and to be considered in pre-alpha stage. | |||
|
|||
The implementation of the java-only module support is inspired by https://github.com/tbroyer/gradle-apt-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.
👍
applyAndroid(project, project.android.applicationVariants) | ||
} else if (project.plugins.hasPlugin("com.android.library")) { | ||
applyAndroid(project, project.android.libraryVariants) | ||
} else if (project.plugins.hasPlugin('java')) { | ||
applyJava(project) | ||
} else { | ||
throw new StopExecutionException("The 'android' plugin is required.") |
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 message doesn't seem up to date anymore.
|
||
public class AndroidNonNullPlugin implements Plugin<Project> { | ||
|
||
void apply(Project project) { | ||
|
||
if (project.plugins.hasPlugin("com.android.application")) { | ||
if (project.plugins.hasPlugin('com.android.application')) { | ||
applyAndroid(project, project.android.applicationVariants) | ||
} else if (project.plugins.hasPlugin("com.android.library")) { |
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.
Can we have single quotes here as well?
task.outputDir = project.file("${project.buildDir}/generated/source/nonNull/${variant.dirName}") | ||
task.variant = variant | ||
def outputPath = "${project.buildDir}/generated/source/nonNull/${variant.dirName}" | ||
def sourceSets = variant.sourceSets |
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.
Can this be inlined?
def task = project.task("generate${taskName.capitalize()}NonNullAnnotations", type: GeneratePackageAnnotationsTask) | ||
task.outputDir = project.file(outputPath) | ||
task.sourceSets = sourceSets | ||
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.
I think this here might work as well:
project.task(...) {
outputDir = ...
sourceSets = ...
}
It returns the created task, so no need to define any local variable.
String taskName = "main".equals(sourceSetName) ? '' : sourceSetName | ||
|
||
def generatedSourcesDir = "${project.buildDir}/generated/source/nonNull/${sourceSet.name}" | ||
GeneratePackageAnnotationsTask task = createTask(project, taskName, generatedSourcesDir, [sourceSet]) |
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.
Do we need this specific type, or could we just have a Task
here?
|
||
// inspired by https://github.com/tbroyer/gradle-apt-plugin/blob/master/src/main/groovy/net/ltgt/gradle/apt/AptPlugin.groovy#L171-L213 | ||
private static void configureIdeaModule(Project project) { | ||
// so the user does not need to apply it when using the 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.
Hm, I'm not sure about that. If the user doesn't care about idea, I'd rather not force it. There's other IDEs out there. ;)
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.
Downloading Eclipse now.
Something I haven't been done for a long long time. 😈
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.
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 think it's better to let the user apply the plugin (as gradle-apt-plugin
does).
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'm embarrassed. The screenshot was like that because I opened the project that already has the files.
We tried with Eclipse with a brand new clone of the project. With or without idea
plugin, we couldn't make it work.
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.
As side note, we also couldn't make the NonNull annotation work.
def generatedSourcesDir = new File("${project.buildDir}/generated/source/nonNull/${sourceSet.name}") | ||
|
||
project.afterEvaluate { | ||
project.idea.module { |
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 is inspired by https://github.com/tbroyer/gradle-apt-plugin , right?
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.
Exactly.
It was only checking if the idea
plugin is applied. We just removed that.
apply plugin: 'java' | ||
apply plugin: com.novoda.gradle.nonnull.AndroidNonNullPlugin | ||
|
||
sourceCompatibility = "1.7" |
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.
Single quotes?
import org.junit.ClassRule | ||
import org.junit.Test | ||
import org.junit.rules.TestRule | ||
import org.junit.runner.Description | ||
import org.junit.runners.model.Statement | ||
|
||
|
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.
?
…ess the parameter via owner. owner does not work to access method parameters above the closure
…here. This requires the `idea` plugin to be applied manually, if the project using the plugin is developed under IntelliJ Idea.
And use constant in SourceSet instead of hardcoded value
PT-391
Description
This PR adds support for java-only modules to the gradle-nonnull-plugin.
Problem: The generated folders are not picked up by IDEA as source folders in java-only modules, see this ticket.
Details
We're applying the
idea
plugin programatically to add the generated folder as source folder.Tests
We added a test that verifies the generated folder in our java-only module is added to the
generatedSourceDirectories
.Paired with @tasomaniac