-
Notifications
You must be signed in to change notification settings - Fork 51
Convert existing Eclipse plugins and apps to Gradle
Conversion of existing Eclipse plugins and apps to Gradle is very easy, if we do it with the help of Wuff gradle plugin. The Eclipse projects themselves do not need to be restructured or even facilitated with "build.gradle" - Wuff does all work for us.
Lets try the following simple scenario: we create two Eclipse projects: one is plugin with a view, another is RCP app using the plugin. Then we convert these two to Gradle, using Wuff.
First three parts of this tutorial are done in Eclipse IDE, the last part - in file explorer and console.
- Invoke menu "File/New/Project...", New Wizard dialog pops up.
- Select "Plug-in Project", click "Next".
- Enter project name "MyPlugin", leave all other fields default, click "Next".
- Choose whatever name and ID for project, make sure that "Rich Client Application" is set to "No", click "Next".
- Choose template "Plug-in with a view", click "Next".
- Choose whatever package and class names, view category. Click "Finish".
- Invoke menu "File/New/Project...", New Wizard dialog pops up.
- Select "Plug-in Project", click "Next".
- Enter project name "MyRcpApp", leave all other fields default, click "Next".
- Choose whatever name and ID for project, make sure that "Rich Client Application" is set to "Yes", click "Next".
- Choose template "Hello RCP", click "Next".
- Choose whatever package and class names, click "Finish".
- Double-click "MyRcpApp/META-INF/MANIFEST.MF", switch to tab "Dependencies".
- Click "Add", "Plug-in Selection" dialog appears. Enter symbolic name of the Eclipse plugin we created previously ("MyPlugin", if symbolic name wasn't changed). Click "OK".
- Save manifest (Ctrl+S).
- Switch to "plugin.xml" tab, insert fragment:
<extension point="org.eclipse.ui.perspectiveExtensions">
<perspectiveExtension targetID="*">
<view standalone="true"
minimized="false"
relative="org.eclipse.ui.editorss"
relationship="left"
id="myplugin.views.SampleView">
</view>
</perspectiveExtension>
</extension>
- Save "plugin.xml" (Ctrl+S).
- Open the directory containing both projects (MyPlugin and MyRcpApp) with a file explorer.
- Create file "settings.gradle" in that directory, insert code:
rootProject.projectDir.listFiles({ new File(it, 'build.properties').isFile() } as FileFilter).each { File subdir ->
include subdir.absolutePath.substring(rootProject.projectDir.absolutePath.length() + 1).replace(File.separator, ':')
}
Explanation: we organize multi-project build (it could contain not only two, but hundreds of Eclipse projects). The projects are auto-discovered by Gradle: if subdirectory contains file "build.properties" (which is Eclipse-specific), it is considered to be a project.
- Create file "build.gradle" in the same directory, insert code:
buildscript {
repositories {
mavenLocal()
jcenter()
}
dependencies {
classpath 'org.akhikhl.wuff:wuff-plugin:+'
}
}
subprojects {
repositories {
mavenLocal()
jcenter()
}
apply plugin: 'java'
if(name == 'MyRcpApp')
apply plugin: 'org.akhikhl.wuff.eclipse-rcp-app'
else
apply plugin: 'org.akhikhl.wuff.eclipse-bundle'
}
Explanation: we configure maven repositories and include wuff-plugin. Then we iterate all subprojects and apply either 'eclipse-bundle' plugin or 'eclipse-rcp-app'.
- Open console in the directory containing "build.gradle" and "settings.gradle", enter:
gradle build
Check: upon successful build there is directory "MyRcpApp/build/output" containing RCP product, specific to our current platform. The product can be started via launch script (.bat or .sh, depending on current platform).
Explanation: Wuff analysed manifests and plugin.xml of all projects, generated inter-project dependencies and eclipse-specific dependencies, generated products. This is a lot of work, which now we don't have to do manually.
Hint: we can inspect dependencies by command gradle dependencies
. The output is huge, so redirect it to the file and then inspect. For the example above you'll see a charming thing: Wuff automatically injects the dependency of project MyRcpApp on MyPlugin. This is because we added MyPlugin to the manifest of MyRcpApp and Wuff translated it to project dependency.