Skip to content

Commit 9434783

Browse files
committed
!!! TODO basic_118 Hello Publishing Library!
1 parent 6b54ef1 commit 9434783

5 files changed

Lines changed: 156 additions & 176 deletions

File tree

.circleci/config.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ jobs:
3939
# about Gradle
4040
- run: ./gradlew --version
4141

42-
# project libraries
43-
- run: ./gradlew dependencies
42+
# # project libraries
43+
# - run: ./gradlew dependencies
4444

45-
# run application
46-
- run: ./gradlew -q app:run
45+
# # run application
46+
# - run: ./gradlew -q app:run
4747

48-
# build application
49-
- run: ./gradlew app:installDist
48+
# # build application
49+
# - run: ./gradlew app:installDist
5050

51-
# run application on OS System
52-
- run: ./app/build/install/app/bin/basic_115
51+
# # run application on OS System
52+
# - run: ./app/build/install/app/bin/basic_118

README.md

Lines changed: 94 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/shyiko/jabba?label=jabba&logo=jabba)](https://github.com/shyiko/jabba)
88
[![Java zulu-openjdk:11](https://img.shields.io/badge/Java-zulu%20openjdk:11-brightgreen?style=flat&logo=java)](https://www.azul.com/downloads/zulu-community/?package=jdk)
99
[![GitHub release (latest by date)](https://img.shields.io/badge/Gradle-v6.7.1-black?style=flat&logo=gradle)](https://gradle.org/)
10-
[![CircleCI](https://circleci.com/gh/cnruby/gradle_java/tree/basic_115.svg?style=svg)](https://app.circleci.com/pipelines/github/cnruby/gradle_java?branch=basic_115)
11-
[![Release--basic_115](https://github.com/cnruby/gradle_java/workflows/Release--basic_115/badge.svg?branch=basic_115)](https://github.com/cnruby/gradle_java/actions)
10+
[![CircleCI](https://circleci.com/gh/cnruby/gradle_java/tree/basic_118.svg?style=svg)](https://app.circleci.com/pipelines/github/cnruby/gradle_java?branch=basic_118)
11+
[![Release--basic_118](https://github.com/cnruby/gradle_java/workflows/Release--basic_118/badge.svg?branch=basic_118)](https://github.com/cnruby/gradle_java/actions)
1212

1313

1414
---
1515

16-
basic_115
17-
<h1>Lesson 115: Hello Own Library!</h1>
16+
!!! TODO basic_118 Hello Publishing Library!
17+
<h1>Lesson 118: Hello Publishing Library!</h1>
1818

1919
- Delevop a multi-project with Java Appliction and Own Java Library
2020
- Develop a multi-project from a project with single application
@@ -26,18 +26,14 @@ basic_115
2626
- [Keywords](#keywords)
2727
- [Prerequisites](#prerequisites)
2828
- [Create a Java Project from GitHub.com](#create-a-java-project-from-githubcom)
29-
- [Develop the Java multi-project](#develop-the-java-multi-project)
30-
- [view the structure of a multi-project](#view-the-structure-of-a-multi-project)
31-
- [change the setting file `settings.gradle`](#change-the-setting-file-settingsgradle)
32-
- [add two subprojects to this project](#add-two-subprojects-to-this-project)
29+
- [Develop the Gradle build file](#develop-the-gradle-build-file)
30+
- [add a gralde properties file `gradle.properties`](#add-a-gralde-properties-file-gradleproperties)
3331
- [Develop the subproject `lib`](#develop-the-subproject-lib)
3432
- [change the gradle build file `lib/build.gradle`](#change-the-gradle-build-file-libbuildgradle)
35-
- [change the Java file for subproject `lib`](#change-the-java-file-for-subproject-lib)
3633
- [Develop the subproject `app`](#develop-the-subproject-app)
3734
- [change the gradle build file `app/build.gradle`](#change-the-gradle-build-file-appbuildgradle)
38-
- [change the Java file for subproject `app`](#change-the-java-file-for-subproject-app)
39-
- [build the main Java application](#build-the-main-java-application)
40-
- [run the java application for the subproject `app`](#run-the-java-application-for-the-subproject-app)
35+
- [check, build and run the main Java application](#check-build-and-run-the-main-java-application)
36+
- [Publish the Library](#publish-the-library)
4137
- [Download and Use This complete Project](#download-and-use-this-complete-project)
4238
- [Referenecs](#referenecs)
4339

@@ -60,7 +56,7 @@ basic_115
6056

6157
```bash
6258
# DO (open a new terminal)
63-
EXISTING_APP_ID=104 && NEW_APP_ID=115 \
59+
EXISTING_APP_ID=115 && NEW_APP_ID=118 \
6460
&& git clone -b basic_${EXISTING_APP_ID} \
6561
https://github.com/cnruby/gradle_java.git ${NEW_APP_ID}_gradle_java \
6662
&& cd ${NEW_APP_ID}_gradle_java
@@ -73,114 +69,28 @@ EXISTING_APP_ID=104 && NEW_APP_ID=115 \
7369

7470

7571

76-
## Develop the Java multi-project
72+
## Develop the Gradle build file
7773

78-
### view the structure of a multi-project
74+
### add a gralde properties file `gradle.properties`
7975

8076
```bash
81-
# DO (check the multi-project)
82-
./gradlew -q projects
77+
# DO (create a file ./gradle.properties)
78+
touch ./gradle.properties
8379

84-
# >> Result
85-
------------------------------------------------------------
86-
Root project
87-
------------------------------------------------------------
88-
89-
Root project '_gradle_java'
90-
No sub-projects
91-
```
92-
93-
### change the setting file `settings.gradle`
94-
95-
```bash
96-
# DO (edit the file "./settings.gradle")
97-
nano ./settings.gradle
98-
99-
# FILE (./settings.gradle)
100-
rootProject.name = '_gradle_java'
101-
include ("app", "lib")
102-
103-
104-
# DO (check the multi-project again)
105-
./gradlew -q projects
80+
# DO (edit the file ./gradle.properties)
81+
nano ./gradle.properties
10682

107-
# >> Result
108-
------------------------------------------------------------
109-
Root project
110-
------------------------------------------------------------
111-
112-
Root project '_gradle_java'
113-
+--- Project ':app'
114-
\--- Project ':lib'
115-
```
116-
117-
118-
## add two subprojects to this project
119-
120-
```bash
121-
# DO (make two subproject folders)
122-
mkdir app lib
123-
124-
# DO (copy the current project build file `build.gradle` to subprojects root folder)
125-
xargs -n 1 cp -v build.gradle <<< "./app/ ./lib/"
126-
127-
# DO (copy the current project `src` folder to subprojects root folder)
128-
xargs -n 1 cp -vr src <<< "./app/ ./lib/"
129-
130-
# DO (remvoe the the current project build file `build.gradle` and folder `src`)
131-
rm build.gradle && rm -rf src
132-
133-
# DO (remove the testing java file)
134-
rm app/src/test/java/de/iotoi/AppTest.java lib/src/test/java/de/iotoi/AppTest.java
135-
```
136-
137-
```bash
138-
# DO (add description to subproject `app`)
139-
nano app/build.gradle
140-
141-
# FILE (app/build.gradle)
142-
...
143-
description = 'The main application for the project'
144-
...
145-
```
146-
147-
```bash
148-
# DO (add description to subproject `lib`)
149-
nano lib/build.gradle
150-
151-
# FILE (lib/build.gradle)
152-
...
153-
// id 'application'
154-
id 'java-library'
155-
...
156-
description = 'The library for the subproject `app`'
157-
...
158-
// application {
159-
// // Define the main class for the application.
160-
// mainClass = "de.iotoi.App"
161-
// }
162-
...
163-
```
164-
165-
```bash
166-
# DO (check the multi-project again)
167-
./gradlew -q projects
168-
169-
# >> Result
170-
------------------------------------------------------------
171-
Root project
172-
------------------------------------------------------------
173-
174-
Root project '_gradle_java'
175-
+--- Project ':app' - The main application for the project
176-
\--- Project ':lib' - The library for the subproject `app`
83+
# FILE (./gradle.properties)
84+
applicationName=basic_118
85+
group=de.iotoi
86+
description=Hello Publishing Library!
87+
version=0.118.1
17788
```
17889

17990

18091

18192
## Develop the subproject `lib`
18293

183-
18494
### change the gradle build file `lib/build.gradle`
18595

18696
```bash
@@ -190,32 +100,54 @@ nano lib/build.gradle
190100
plugins {
191101
id 'java'
192102
id 'java-library'
103+
id 'com.jfrog.bintray' version '1.8.5'
104+
id 'maven-publish'
193105
}
194106

195-
group = 'de.iotoi'
196107
sourceCompatibility = JavaVersion.VERSION_11
108+
apply from: System.getenv("HOME") + "/jcenter.properties"
197109

198-
description = 'The library for the subproject `app`'
199-
200-
repositories {
201-
jcenter()
202-
}
110+
repositories { jcenter() }
203111
dependencies {}
204112
test {}
205-
```
206113

207-
### change the Java file for subproject `lib`
114+
task sourcesJar(type: Jar, dependsOn: classes){
115+
classifier = 'sources'
116+
from sourceSets.main.allSource
117+
}
208118

209-
```bash
210-
# DO (change the java file `lib/src/main/java/de/iotoi/App.java`)
211-
mv lib/src/main/java/de/iotoi/App.java lib/src/main/java/de/iotoi/Lib.java
119+
artifacts{
120+
archives sourcesJar
121+
}
212122

213-
# FILE (lib/src/main/java/de/iotoi/Lib.java)
214-
package de.iotoi;
123+
publishing{
124+
publications{
125+
"$project.name"(MavenPublication){
126+
from components.java
127+
groupId project.findProperty("group")
128+
artifactId archivesBaseName
129+
version project.findProperty("version")
130+
artifact sourcesJar
131+
}
132+
}
133+
}
215134

216-
public class Lib {
217-
public String getGreeting() {
218-
return "Hello world.";
135+
bintray{
136+
user = project.findProperty("bintrayUser")
137+
key = project.findProperty("bintrayApiKey")
138+
publications = ["$project.name"]
139+
publish = true // !!!
140+
pkg{
141+
repo = 'gradle_java_jcenter'
142+
name = project.findProperty("applicationName")
143+
desc = project.findProperty("description")
144+
licenses = ['Apache-2.0']
145+
vcsUrl = 'https://github.com/cnruby/gradle_java'
146+
labels = ['java, demo, jcenter, library, gradle, bintray, publish']
147+
version {
148+
name = project.findProperty("version")
149+
released = new Date()
150+
}
219151
}
220152
}
221153
```
@@ -235,18 +167,7 @@ nano app/build.gradle
235167
id 'application'
236168
}
237169

238-
startScripts {
239-
applicationName = 'basic_115'
240-
group = 'de.iotoi'
241-
// version = '1.1.5'
242-
sourceCompatibility = JavaVersion.VERSION_11
243-
}
244-
245-
description = 'The main application for the project'
246-
247-
repositories {
248-
jcenter()
249-
}
170+
repositories { jcenter() }
250171

251172
dependencies {
252173
implementation project(':lib')
@@ -259,50 +180,67 @@ nano app/build.gradle
259180
test {}
260181
```
261182
262-
### change the Java file for subproject `app`
263183
264-
```bash
265-
# DO (change the java file `app/src/main/java/de/iotoi/App.java`)
266-
nano app/src/main/java/de/iotoi/App.java
267184
268-
# FILE (app/src/main/java/de/iotoi/App.java)
269-
package de.iotoi;
185+
## check, build and run the main Java application
270186
271-
public class App {
272-
public static void main(String[] args) {
273-
System.out.println(new Lib().getGreeting());
274-
}
275-
}
187+
```bash
188+
# DO (build subproject `app` and `lib`)
189+
./gradlew -q check
190+
# >> Result: nothing
276191
```
277192
278-
### build the main Java application
279-
280193
```bash
281194
# DO (build subproject `app` and `lib`)
282195
./gradlew clean app:build
283196
```
284197
285-
### run the java application for the subproject `app`
286-
287198
```bash
199+
# DO (run the java application for the subproject `app` )
288200
./gradlew -q app:run
289-
290201
# >> Result:
291202
Hello world.
292203
```
293204
294205
206+
## Publish the Library
207+
208+
```bash
209+
# DO (check)
210+
./gradlew check
211+
# >> Result: nothing
212+
213+
# DO (build and publsih the java library)
214+
./gradlew clean build bintrayPublish
215+
# >> Result
216+
> Task :lib:bintrayUpload
217+
Uploading to https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1-sources.jar...
218+
Uploaded to 'https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1-sources.jar'.
219+
Uploading to https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1.jar...
220+
Uploaded to 'https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1.jar'.
221+
Uploading to https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1.pom...
222+
Uploaded to 'https://api.bintray.com/content/cnruby/gradle_java_jcenter/basic_118/0.118.1/de/iotoi/lib/0.118.1/lib-0.118.1.pom'.
223+
224+
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
225+
Use '--warning-mode all' to show the individual deprecation warnings.
226+
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
227+
228+
BUILD SUCCESSFUL in 8s
229+
8 actionable tasks: 5 executed, 3 up-to-date
230+
```
231+
232+
295233
296234
## Download and Use This complete Project
297235
298236
```bash
299237
# Download
300-
git clone -b basic_115 https://github.com/cnruby/gradle_java.git basic_115
238+
git clone -b basic_118 https://github.com/cnruby/gradle_java.git basic_118
301239
```
302240
303241
```bash
304242
# Usage for the project
305-
google-chrome https://github.com/cnruby/gradle_java/releases/tag/v0.115.1
243+
google-chrome https://github.com/cnruby/gradle_java/releases/tag/v0.118.1
306244
```
307245
308246

0 commit comments

Comments
 (0)