Gave up on buildSrc/build.gradle
.
Now I’m looking into a custom plugin, initially under the buildSrc
folder until I get it working.
The goal is for somebody working on a native binary project to apply this custom plugin to their project’s build script, and, with no other configuration or closures specified in their build script, be able to run .\gradlew <component>VisualStudio
task and produce the customized Visual Studio solution and project file content defined in this custom plugin.
For example, I’d like for this custom plugin to produce the same results as if I’d had this content in the target project’s build script:
model {
visualStudio {
solutions.all {
solutionFile.withContent { TextProvider content ->
content.text = content.text.replace( project.projectDir.getAbsolutePath(), ".")
content.text = content.text.replaceAll( "Microsoft Visual Studio Solution File, Format Version [0-9]+\\.[0-9]+",
"Microsoft Visual Studio Solution File, Format Version 12.00")
content.text = content.text.replace( "# Visual C++ Express 2010", "# Visual Studio 2013" )
def builder = content.asBuilder()
def versionIndex = builder.indexOf("# Visual Studio 2013" )
builder.insert(versionIndex + 20, """
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 12.0.21005.1
""")
}
}
}
}
And I’d like for that to be possible by simply applying this custom plugin.
That is, apply plugin: customVisualCppPlugin
would be all you’d need to do so that you could run gradlew componentVisualStudio
and get this customized Visual Studio solution file out.
So far, all I’ve got is a skeletal plugin that applies the visual-studio
plugin like so:
import org.gradle.api.Project;
import org.gradle.api.Plugin;
import org.gradle.ide.visualstudio.plugins.VisualStudioPlugin;
class CommonVisualCppPlugin implements Plugin<Project> {
void apply(Project theProject) {
def pluginManager = theProject.getPluginManager();
pluginManager.apply( VisualStudioPlugin );
}
}
…but I’m at a complete loss now for how, from this plugin, to apply the common Visual Studio solution file contents. I’m looking for something that will work regardless of whether or not the target project has defined model { visualStudio {} }
.
I’ve tried doing simple-seeming operations within the apply()
method like:
theProject.extensions.visualStudio { solutions.all { /* custom content here */ } }
…but of course this just flat out fails. I’m pretty much trying all kinds of random stuff that probably has no hope of working. Any suggestions are definitely welcome.
@Daniel_L: sorry to ping you again, but is what I’m trying to achieve even possible? If so, what would it look like? Is a custom plugin even the right approach?
Thanks…