kec2
(Klaus Christiansen)
February 6, 2019, 1:29pm
1
I have project with some modules that have sub-modules.
If i run gradle clean-eclipse eclipse on a top-module then eclipse for all modules below is updated.
Is there a way to only update the eclipse files in a certain module? I would like to take it slow. One module at the time.
Mehtrick
(Mehtrick)
February 6, 2019, 8:32pm
2
The -p parameter sets the project on which the task should be executed.
gradle -p "modulename" cleanEclipse eclipse
kec2
(Klaus Christiansen)
February 7, 2019, 6:32am
3
Yes, but it still affects the modules below it. Not just the single one.
kec2
(Klaus Christiansen)
June 18, 2019, 7:38am
4
does anyone have the answer to my question?
Lance
(uklance)
June 18, 2019, 10:44am
5
You should be able to do
gradle :foo:cleanEclipse :foo:eclipse
Where “foo” is your module name
kec2
(Klaus Christiansen)
June 20, 2019, 7:25am
6
This is better but not good enough.
The eclipseProject task is still executes on sub-projects. I would like that no eclipse* tasks are executed on sub-projects.
Lance
(uklance)
June 20, 2019, 7:47am
7
As a first step, let’s understand the task dependencies so that we can disable them. You can use the Gradle Task Tree Plugin to see the task dependencies
eg:
plugins {
id "com.dorongold.task-tree" version "1.3"
}
Then run
gradle :foo:cleanEclipse :foo:eclipse taskTree
And copy/paste the output
1 Like
kec2
(Klaus Christiansen)
June 26, 2019, 8:32am
8
Lance:
taskTree
Project Foo has a dependency on Bar.
Also I’m haven the eclipse task depending on cleanEclipse.
D:\workspaces\SomeProject\Foo>gradle :eclipse :taskTree
> Task :taskTree
------------------------------------------------------------
Root project
------------------------------------------------------------
:eclipse
+--- :cleanEclipse
| +--- :cleanEclipseClasspath
| +--- :cleanEclipseJdt
| \--- :cleanEclipseProject
+--- :eclipseClasspath
+--- :eclipseJdt
+--- :eclipseProject
\--- :Bar:eclipseProject
It changes the .project file in Bar. Spaces becomes tabs and things are ordered differently.
Lance
(uklance)
June 26, 2019, 10:07am
9
You could do something like
gradle.taskGraph.whenReady { taskGraph ->
List<Task> eclipseTasks = taskGraph.allTasks.findAll { it.name.toLowerCase().contains('eclipse') }
if (eclipseTasks) {
Set<Project> sortedProjects = new TreeSet<>(new ProjectComparator())
sortedProjects.addAll(eclipseTasks*.project)
// find the highest level project
Project topProject = sortedProjects.iterator().next()
// disable any eclipse tasks that aren't for the top project
eclipseTasks.findAll { it.project != topProject}*.enabled = false
}
}
class ProjectComparator implements Comparator<Project> {
int compare(Project left, Project right) {
return left == right ? 0
: isParent(left, right) ? -1
: isParent(right, left) ? 1
: left.name.compareTo(right.name)
}
}
boolean isParent(Project left, Project right) {
Project current = right
while (current != null) {
if (left == current.parent) return true
current = current.parent
}
return false
}
}
kec2
(Klaus Christiansen)
June 27, 2019, 8:09am
10
That is not an acceptable solution.
I think that there should be a flag on the Eclipse plugin that enables/disables modifying eclipse files on sub-projects.
Lance
(uklance)
June 27, 2019, 8:32pm
11
That is not an acceptable solution.
You could move ProjectComparator
from build.gradle
to buildSrc/src/main/groovy/ProjectComparator.groovy
if you want to clean it up a bit