Skip to content

Commit 0809319

Browse files
committed
Merge pull request #131 from brunobowden/plugin-publish
Workaround for plugins {} + Usage Instructions
2 parents 6a0fd13 + b8abd68 commit 0809319

File tree

6 files changed

+63
-48
lines changed

6 files changed

+63
-48
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,4 @@ git push -f
8686
```
8787

8888
For guidance on doing the merge itself, see
89-
http://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging
89+
https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,30 @@ You may wish to wait for the beta release as we will not support the alpha relea
77

88
You should start with a clean java only project without any android dependencies, preferably named `'shared'`. This must be buildable using Gradle's standard `'java'` plugin. It may start as an empty project and allows you to gradually shift over code from an existing Android application.
99

10-
Within the `'shared'` project's `build.gradle`, apply the j2objc plugin before the java plugin:
11-
12-
// 'shared' build.gradle
13-
plugins {
14-
id "com.github.j2objccontrib.j2objcgradle" version "0.2.1-alpha"
10+
Within the `'shared'` project's `build.gradle`, apply the j2objc plugin before the java plugin.
11+
12+
Note: the plugins {...} syntax does not work for the j2objc plugin, so you must use the old buildscript style
13+
For more info see: https://github.com/j2objc-contrib/j2objc-gradle/issues/130
14+
15+
// File: shared/build.gradle
16+
buildscript {
17+
repositories {
18+
maven {
19+
url "https://plugins.gradle.org/m2/"
20+
}
21+
}
22+
dependencies {
23+
// Current Version: https://plugins.gradle.org/plugin/com.github.j2objccontrib.j2objcgradle
24+
classpath "gradle.plugin.com.github.j2objccontrib.j2objcgradle:j2objc-gradle:X.Y.Z-alpha"
25+
}
1526
}
27+
1628
apply plugin: 'java'
29+
apply plugin: 'com.github.j2objccontrib.j2objcgradle'
1730

1831
Within the Android application's project `build.gradle`, make it dependent on the `shared` project:
1932

20-
// 'android-app' build.gradle
33+
// File: android/build.gradle
2134
dependencies {
2235
compile project(':shared')
2336
}
@@ -28,13 +41,15 @@ The preferred folder structure is:
2841
│ .gitignore
2942
│ build.gradle
3043
├───android
31-
| │ build.gradle // dependency on ':shared'
32-
| └ src // src/main/java/...
44+
│ build.gradle // dependency on ':shared'
45+
└ src // src/main/java/...
3346
├───shared
34-
| │ build.gradle // apply 'j2objc' then 'java' plugins
35-
| │ build/j2objcOutputs // j2objc generated headers and libraries
36-
| └ src // src/main/java/...
37-
└───Xcode
47+
│ │ build.gradle // apply 'j2objc' then 'java' plugins
48+
│ ├ build // build directory
49+
│ │ │ ... // build output
50+
│ │ └ j2objcOutputs // j2objc generated headers and libraries
51+
│ └ src // src/main/java/...
52+
└───xcode
3853
│ Project
3954
└ ProjectTests
4055

@@ -51,11 +66,13 @@ java project's build.gradle:
5166
```
5267
buildscript {
5368
dependencies {
54-
classpath files('/PATH_TO_J2OBJC_PLUGIN/j2objc-gradle/build/libs/j2objc-gradle-0.1.0-alpha.jar')
69+
// Update using "version = X.Y.Z-alpha" defined in build.gradle
70+
classpath files('/PATH_TO_J2OBJC_PLUGIN/j2objc-gradle/build/libs/j2objc-gradle-X.Y.Z-alpha.jar')
5571
}
5672
}
5773
58-
apply plugin: 'j2objc'
74+
apply plugin: 'java'
75+
apply plugin: 'com.github.j2objccontrib.j2objcgradle'
5976
6077
// (regular j2objcConfig here...)
6178
```

build.gradle

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,37 @@
1414
* limitations under the License.
1515
*/
1616

17+
// Based on https://plugins.gradle.org/docs/publish-plugin
18+
19+
// First, apply the publishing plugin
20+
plugins {
21+
id "com.gradle.plugin-publish" version "0.9.0"
22+
}
1723
apply plugin: 'groovy'
18-
apply plugin: 'java'
19-
apply plugin: 'maven'
2024

2125
dependencies {
2226
compile gradleApi()
23-
compile localGroovy()
2427
}
2528

29+
2630
task wrapper(type: Wrapper) {
2731
gradleVersion = '2.4'
2832
distributionUrl = 'https://services.gradle.org/distributions/gradle-2.4-all.zip'
2933
}
3034

31-
repositories {
32-
mavenCentral()
33-
}
34-
3535
group = 'com.github.j2objccontrib.j2objcgradle'
36-
version = '0.2.0-alpha'
36+
version = '0.2.1-alpha'
3737

38-
dependencies {
39-
testCompile group: 'junit', name: 'junit', version: '4.12'
40-
}
38+
pluginBundle {
39+
website = 'https://www.github.com/j2objc-contrib/j2objc-gradle/'
40+
vcsUrl = 'https://github.com/j2objc-contrib/j2objc-gradle'
41+
description = 'J2ObjC Gradle Build Plugin'
42+
tags = ['j2objc']
4143

44+
plugins {
45+
j2objcPlugin {
46+
id = 'com.github.j2objccontrib.j2objcgradle'
47+
displayName = 'J2ObjC Gradle Build Plugin'
48+
}
49+
}
50+
}

src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPlugin.groovy

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,13 @@ class J2objcPlugin implements Plugin<Project> {
7575
if (!plugins.hasPlugin('java')) {
7676
def message =
7777
"j2objc plugin didn't find the 'java' plugin in the '${project.name}' project.\n"+
78-
"This is a requirement for using j2objc. If you are migrating an existing\n" +
79-
"Android app, it is suggested that you create a separate project that is\n" +
80-
"named 'shared'. This should not have any android dependencies. Then gradually\n"
81-
"migrate shared code there. Within that project, first apply the 'java' then\n"
82-
"'j2objc' plugins by adding the following lines to the build.gradle file:\n" +
78+
"This is a requirement for using j2objc. Please see usage information at:\n" +
8379
"\n" +
84-
"apply plugin: 'java'\n" +
85-
"apply plugin: 'j2objc'\n" +
86-
"\n" +
87-
"j2objcConfig {\n" +
88-
" // j2objc settings here\n" +
89-
"}\n" +
90-
"\n" +
91-
"More Info: https://github.com/j2objc-contrib/j2objc-gradle/#usage"
80+
"https://github.com/j2objc-contrib/j2objc-gradle/#usage"
9281
throw new InvalidUserDataException(message)
9382
}
9483

95-
extensions.create("j2objcConfig", J2objcPluginExtension)
84+
extensions.create('j2objcConfig', J2objcPluginExtension)
9685
afterEvaluate { evaluatedProject ->
9786
// Validate minimally required parameters.
9887
// j2objcHome() will throw the appropriate exception internally.
@@ -109,20 +98,20 @@ class J2objcPlugin implements Plugin<Project> {
10998

11099
// If users need to generate extra files that j2objc depends on, they can make this task dependent
111100
// on such generation.
112-
tasks.create(name: "j2objcPreBuild", type: DefaultTask,
101+
tasks.create(name: 'j2objcPreBuild', type: DefaultTask,
113102
dependsOn: 'test') {
114103
description "Marker task for all tasks that must be complete before j2objc building"
115104
}
116105

117-
tasks.create(name: "j2objcCycleFinder", type: J2objcCycleFinderTask,
106+
tasks.create(name: 'j2objcCycleFinder', type: J2objcCycleFinderTask,
118107
dependsOn: 'j2objcPreBuild') {
119108
description "Run the cycle_finder tool on all Java source files"
120109
}
121110

122111
// TODO @Bruno "build/source/apt" must be project.j2objcConfig.generatedSourceDirs no idea how to set it
123112
// there
124113
// Dependency may be added in project.plugins.withType for Java or Android plugin
125-
tasks.create(name: "j2objcTranslate", type: J2objcTranslateTask,
114+
tasks.create(name: 'j2objcTranslate', type: J2objcTranslateTask,
126115
dependsOn: 'j2objcCycleFinder') {
127116
description "Translates all the java source files in to Objective-C using j2objc"
128117
additionalSrcFiles = files(
@@ -138,13 +127,14 @@ class J2objcPlugin implements Plugin<Project> {
138127

139128
// Note the 'debugTestJ2objcExecutable' task is dynamically created by the objective-c plugin applied
140129
// on the above line. It is specified by the testJ2objc native component.
141-
tasks.create(name: "j2objcTest", type: J2objcTestTask,
130+
tasks.create(name: 'j2objcTest', type: J2objcTestTask,
142131
dependsOn: ['test', 'debugTestJ2objcExecutable']) {
132+
// This transitively depends on the 'test' task from the java plugin
143133
description 'Runs all tests in the generated Objective-C code'
144134
testBinaryFile = file("${buildDir}/binaries/testJ2objcExecutable/debug/testJ2objc")
145135
}
146-
// 'check' task is added by 'java' plugin, it depends on 'test' and all the other verification tasks,
147-
// now including 'j2objcTest'.
136+
// 'check' task is added by 'java' plugin, it depends on 'test' and
137+
// all the other verification tasks, now including 'j2objcTest'.
148138
lateDependsOn(project, 'check', 'j2objcTest')
149139

150140
tasks.create(name: 'j2objcPackLibrariesDebug', type: J2objcPackLibrariesTask,

src/main/groovy/com/github/j2objccontrib/j2objcgradle/J2objcPluginExtension.groovy

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ class J2objcPluginExtension {
5959
// TRANSLATE
6060
// Flags copied verbatim to j2objc command.
6161
// A list of all possible flag can be found here:
62-
// https://github.com/google/j2objc/blob/master/translator/src/main/resources/com/google/devtools/j2objc/J2ObjC
63-
// .properties
62+
// https://github.com/google/j2objc/blob/master/translator/src/main/resources/com/google/devtools/j2objc/J2ObjC.properties
6463
String translateFlags = ""
6564
// -classpath library additions from ${projectDir}/lib/, e.g.: "json-20140107.jar", "somelib.jar"
6665
String[] translateClassPaths = []

0 commit comments

Comments
 (0)