-
Notifications
You must be signed in to change notification settings - Fork 23
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
Complex plugin setup fix #71
Closed
Closed
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
70dc3ad
Fixed issue where the plugin won't load if its not applied in the exa…
scphantm f89c7c7
Added grooovydoc capability
scphantm d003f24
Rebuild the publication tasks to enable them to be created easier by …
scphantm d0e7eec
Hacked in the new nebula-test and got the unit tests windows compatible
scphantm ce7e145
Upgrade to latest plugin.plugin and stripped out windows hacks
scphantm fdfa822
Fixed OS Specific bugs with the test suite
scphantm 2989952
trying to figure out why this travis fails, updated some libraries
scphantm 88251b5
had to roll back gradletest
scphantm 7eba596
Merge branch 'master' into ComplexPluginSetupFix
scphantm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/main/groovy/nebula/plugin/publishing/PublicationBase.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package nebula.plugin.publishing | ||
|
||
import nebula.plugin.publishing.ivy.IvyBasePublishPlugin | ||
import nebula.plugin.publishing.maven.MavenBasePublishPlugin | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.Task | ||
import org.gradle.api.publish.ivy.IvyPublication | ||
import org.gradle.api.publish.ivy.plugins.IvyPublishPlugin | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.maven.plugins.MavenPublishPlugin | ||
|
||
trait PublicationBase implements Plugin<Project>, StandardTextValues { | ||
|
||
/** | ||
* Checks to see if the task already exists or not on the project. If it does not, then it creates it. | ||
* @param project project to add the task too | ||
* @param task Map configuration of the task to create | ||
* @return Null if it was not created, the task object if it was. | ||
*/ | ||
Task addTaskLocal(Project project, Map<String, ?> task) { | ||
if (!project.tasks.findByName(task.get('name').toString())) { | ||
project.tasks.create(task) | ||
} else { | ||
null | ||
} | ||
} | ||
|
||
void checkAddMavenPublish(Project project, Task createdTask) { | ||
project.plugins.withType(MavenPublishPlugin) { | ||
project.plugins.apply(MavenBasePublishPlugin) | ||
|
||
project.publishing.publications { | ||
nebula(MavenPublication) { | ||
artifact createdTask | ||
} | ||
} | ||
} | ||
} | ||
|
||
void checkAddIvyPublish(Project project, Task createdTask, String classifier) { | ||
project.plugins.withType(IvyPublishPlugin) { | ||
project.plugins.apply(IvyBasePublishPlugin) | ||
|
||
project.publishing.publications { | ||
nebulaIvy(IvyPublication) { | ||
artifact(createdTask) { | ||
type classifier | ||
conf classifier | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
void buildConfigureTask(Project project, Task createdTask, String classifierString, String dependsOnTask, | ||
String artifactExtension, boolean fromSources = false, sourceSetNames = []) { | ||
|
||
if (createdTask != null) { | ||
/* | ||
the addTaskLocal checks to see if the task already exists or not. If it returns null, | ||
that means it did not create the task. If it returned the task object, then it created it | ||
We dont want to configure things if we didn't create the task | ||
*/ | ||
|
||
// this means it was just created correctly, now reprocess it | ||
def dependsOnTaskObject = project.tasks.getByName(dependsOnTask) | ||
|
||
createdTask.configure { | ||
dependsOn dependsOnTaskObject | ||
if (fromSources) { | ||
sourceSetNames.each { | ||
from project.sourceSets.findByName(it).allSource | ||
} | ||
} else { | ||
from dependsOnTaskObject.destinationDir | ||
} | ||
|
||
classifier classifierString | ||
extension artifactExtension | ||
} | ||
|
||
checkAddMavenPublish(project, createdTask) | ||
checkAddIvyPublish(project, createdTask, classifierString) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/groovy/nebula/plugin/publishing/StandardTextValues.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package nebula.plugin.publishing | ||
|
||
|
||
interface StandardTextValues { | ||
public static final String CORE_GROUP_BUILD = "build" | ||
|
||
public static final String CORE_TASK_GROOVYDOC = "groovydoc" | ||
public static final String CORE_TASK_JAVADOC = "javadoc" | ||
public static final String CORE_TASK_SCALADOC = "scaladoc" | ||
public static final String CORE_TASK_CLASSES = "classes" | ||
|
||
|
||
public static final String TASK_NAME_GROOVYDOC_JAR = "groovydocJar" | ||
public static final String TASK_DESC_GROOVYDOC_JAR = "Jars the groovydoc files for the project" | ||
public static final String TASK_NAME_JAVADOC_JAR = "javadocJar" | ||
public static final String TASK_DESC_JAVADOC_JAR = "Jars the javadoc files for the project" | ||
public static final String TASK_NAME_SCALADOC_JAR = "scaladocJar" | ||
public static final String TASK_DESC_SCALADOC_JAR = "Jars the groovydoc files for the project" | ||
|
||
public static final String TASK_NAME_SOURCE_JAR = "sourceJar" | ||
public static final String TASK_DESC_SOURCE_JAR = "Jars the source files for the project" | ||
|
||
public static final String ARCHIVE_CLASSIFIER_GROOVYDOC = "groovydoc" | ||
public static final String ARCHIVE_CLASSIFIER_SOURCES = "sources" | ||
public static final String ARCHIVE_CLASSIFIER_JAVADOC = "javadoc" | ||
public static final String ARCHIVE_CLASSIFIER_SCALADOC = "scaladoc" | ||
|
||
public static final String EXTENSION_JAR = "jar" | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/groovy/nebula/plugin/publishing/publications/GroovydocJarPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package nebula.plugin.publishing.publications | ||
|
||
import nebula.plugin.publishing.PublicationBase | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.GroovyPlugin | ||
import org.gradle.api.tasks.bundling.Jar | ||
|
||
class GroovydocJarPlugin implements PublicationBase { | ||
@Override | ||
void apply(Project project) { | ||
project.plugins.withType(GroovyPlugin) { | ||
|
||
def groovyJar = addTaskLocal(project, [name : TASK_NAME_GROOVYDOC_JAR, | ||
description: TASK_DESC_GROOVYDOC_JAR, | ||
group : CORE_GROUP_BUILD, | ||
type : Jar]) | ||
|
||
buildConfigureTask(project, groovyJar, ARCHIVE_CLASSIFIER_GROOVYDOC, CORE_TASK_GROOVYDOC, EXTENSION_JAR) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/groovy/nebula/plugin/publishing/publications/ScaladocJarPlugin.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package nebula.plugin.publishing.publications | ||
|
||
import nebula.plugin.publishing.PublicationBase | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.scala.ScalaPlugin | ||
import org.gradle.api.tasks.bundling.Jar | ||
|
||
class ScaladocJarPlugin implements PublicationBase { | ||
@Override | ||
void apply(Project project) { | ||
project.plugins.withType(ScalaPlugin) { | ||
|
||
def scalaJar = addTaskLocal(project, [name : TASK_NAME_SCALADOC_JAR, | ||
description: TASK_DESC_SCALADOC_JAR, | ||
group : CORE_GROUP_BUILD, | ||
type : Jar]) | ||
|
||
buildConfigureTask(project, scalaJar, ARCHIVE_CLASSIFIER_SCALADOC, CORE_TASK_SCALADOC, EXTENSION_JAR) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/gradle-plugins/nebula.groovydoc-jar.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=nebula.plugin.publishing.publications.GroovydocJarPlugin |
1 change: 1 addition & 0 deletions
1
src/main/resources/META-INF/gradle-plugins/nebula.scaladoc-jar.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
implementation-class=nebula.plugin.publishing.publications.ScaladocJarPlugin |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
From my understanding publishing.publications accesses the publishing block, where as the series of closures will apply later when a publishing task is run.
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 has something to do with the timing. ive heard several discussions on what causes it. What i do know for sure is this is universally referred to as the fix and Gradle's answer for the past 2 or so years is publish-maven is in incubation.
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.
Need to see a test that fails with
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.
wow, thats going to be tough because its buried about three layers of custom plugins deep in a CI server. It has to do with the core publish being in the core plugin that everything else inherits, with child plugins and such. Its really tough, I do know its a well known groovy/gradle issue because it only took me a minute or two to find the solution when i hit it. I can track down the research when im on my work machine tomorrow.
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.
researchgate/gradle-release#125
https://stackoverflow.com/questions/28020520/custom-gradle-plugin-causes-cannot-configure-the-publishing-extension
are where i got the fix for the "can not modify publish after its been accessed" error. As i said, its a well known gradle/groovy issue in their maven-publish plugin.
Still trying to figure out a way to boil it down to a unit test. the conditions are pretty specific and not easy to replicate.
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.
http://stackoverflow.com/questions/21190230/how-can-plugin-programmatically-configure-maven-publish-publishing-and-allow-bui
Apparently Justin Ryan built a class in a very early version of nebula publish to try to handle this specific issue. but just changing the syntax is far easier than his fix.
It looks like i have no choice but to build an additional custom plugin (a build.gradle file is nothing more than a plugin). It seams you can't replicate the problem from a single plugin closure, like a build.gradle file. It seems like you can only replicate it from a parent/child plugin relationship, where the parent introduces publishing and finishes its apply method, then a child method attempts to access the publishing from its apply method. At least i think so.
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.
Would it be ok if I put the prelim stuff in https://github.com/nebula-plugins/gradle-nothing-plugin
create a new plugin in that project to use to replicate this here? I can't figure out any other way to replicate it than with an external plugin. but ill keep thinking