Skip to content
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

SCB-457 demostrate how to run spring boot/non spring boot application with gradle #640

Merged
merged 2 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ __pycache__/

# Mac
.DS_Store

# gradle
.gradle
31 changes: 23 additions & 8 deletions samples/bmi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ There are two microservices in this demo.
## Prerequisite
1. [Oracle JDK 1.8+](https://docs.oracle.com/javase/8/docs/technotes/guides/install/install_overview.html)
2. [Maven 3.x](https://maven.apache.org/install.html)
3. [Gradle 4.x](https://gradle.org/install/)(Optional)

## Quick Start(Linux)
1. Run the service center
Expand All @@ -19,12 +20,26 @@ git clone https://github.com/apache/incubator-servicecomb-java-chassis.git
cd incubator-servicecomb-java-chassis/samples
```
3. Run microservices
* Run the **BMI calculator service**
```bash
(cd bmi/calculator; mvn spring-boot:run)
```
* Run the **webapp service**
```bash
(cd bmi/webapp; mvn spring-boot:run)
```
* via maven
* Run the **BMI calculator service**
```bash
(cd bmi/calculator; mvn spring-boot:run)
```
* Run the **webapp service**
```bash
(cd bmi/webapp; mvn spring-boot:run)
```
* via gradle
* Install ServiceComb Java Chassis
```bash
mvn clean install -DskipTests
```
* Run the **BMI calculator service**
```bash
(cd bmi/calculator; gradle bootRun)
```
* Run the **webapp service**
```bash
(cd bmi/webapp; gradle bootRun)
```
4. Visit the services via **<a>http://127.0.0.1:8889</a>**.
54 changes: 54 additions & 0 deletions samples/bmi/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

allprojects {
apply plugin: 'maven'

group = 'org.apache.servicecomb.samples'
version = '1.0.0-m2-SNAPSHOT'
}

buildscript {
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.5.RELEASE")
}
repositories {
mavenLocal()
mavenCentral()
}
}

subprojects {
apply plugin: 'java'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
compile group: 'org.hibernate', name: 'hibernate-validator', version:'5.2.4.Final'
}
}
49 changes: 49 additions & 0 deletions samples/bmi/calculator/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

description = 'Java Chassis::Samples::BMI::Calculator'

dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter') {
exclude(module: 'commons-logging')
}
compile group: 'org.apache.servicecomb', name: 'spring-boot-starter-provider'
compile group: 'org.apache.servicecomb', name: 'handler-flowcontrol-qps'
compile group: 'org.apache.servicecomb', name: 'handler-bizkeeper'
compile group: 'org.apache.servicecomb', name: 'handler-tracing-zipkin'
}

// dependency-management-plugin is a replacement of dependencyManagement in maven
// we need to enable the plugin and specify the dependencyManagement in the following form in each submodule
// according to the official document: https://github.com/spring-gradle-plugins/dependency-management-plugin.
buildscript {
dependencies {
classpath('io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE')
}
repositories {
mavenLocal()
mavenCentral()
}
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comment for it?

imports {
mavenBom 'org.apache.servicecomb:java-chassis-dependencies:1.0.0-m2-SNAPSHOT'
}
}
23 changes: 23 additions & 0 deletions samples/bmi/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

rootProject.name = 'bmi'
include ':bmi-calculator'
include ':webapp'

project(':bmi-calculator').projectDir = "$rootDir/calculator" as File
project(':webapp').projectDir = "$rootDir/webapp" as File
49 changes: 49 additions & 0 deletions samples/bmi/webapp/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

description = 'Java Chassis::Samples::BMI::Webapp'

dependencies {
compile(group: 'org.springframework.boot', name: 'spring-boot-starter') {
exclude(module: 'commons-logging')
}
compile group: 'org.apache.servicecomb', name: 'spring-boot-starter-servicecomb'
compile group: 'org.apache.servicecomb', name: 'spring-boot-starter-discovery'
compile group: 'org.apache.servicecomb', name: 'spring-cloud-zuul'
compile group: 'org.apache.servicecomb', name: 'spring-cloud-zuul-zipkin'
}

// dependency-management-plugin is a replacement of dependencyManagement in maven
// we need to enable the plugin and specify the dependencyManagement in the following form in each submodule
// according to the official document: https://github.com/spring-gradle-plugins/dependency-management-plugin.
buildscript {
dependencies {
classpath('io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE')
}
repositories {
mavenLocal()
mavenCentral()
}
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
imports {
mavenBom 'org.apache.servicecomb:java-chassis-dependencies:1.0.0-m2-SNAPSHOT'
}
}
48 changes: 35 additions & 13 deletions samples/codefirst-sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,52 @@ For detail information please refer to [Doc](http://servicecomb.incubator.apache

2. Start the codefirst-provider service

- Start provider service by maven
- Start provider service via maven

Compile the source code at root directory of ServiceComb Java Chassis, which is `incubator-servicecomb-java-chassis/`, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.
Compile the source code at root directory of ServiceComb Java Chassis, which is `incubator-servicecomb-java-chassis/`, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.

```bash
cd incubator-servicecomb-java-chassis/
mvn clean install -Psamples -DskipTests #only need to install at first time.
cd samples/codefirst-sample/codefirst-provider/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.provider.CodeFirstProviderMain"
```
```bash
cd incubator-servicecomb-java-chassis/
mvn clean install -Psamples -DskipTests #only need to install at first time.
cd samples/codefirst-sample/codefirst-provider/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.provider.CodeFirstProviderMain"
```

- Start provider service by IDE
- Start provider service via gradle

Import the project by InteliJ IDEA or Eclipse, add sample module to pom.xml file in root module `incubator-servicecomb-java-chassis/pom.xml`, and add `<module>samples</module>` to `<modules></modules>` block, Then find `main` function `CodeFirstProviderMain` of provider service and `RUN` it like any other Java program.
Compile the source code at root directory of ServiceComb Java Chassis, which is `incubator-servicecomb-java-chassis/`, and use `mvn exec` to execute the main class `CodeFirstProviderMain`.

3. Start the codefirst-consumer service
```bash
cd incubator-servicecomb-java-chassis/
mvn clean install -Psamples -DskipTests #only need to install at first time.
cd samples/codefirst-sample/codefirst-provider/
gradle clean run
```

- Start provider service via IDE

Just like how to start codefirst-provider service. But the main class of codefirst-consumer service is `CodeFirstConsumerMain`.
Import the project by InteliJ IDEA or Eclipse, add sample module to pom.xml file in root module `incubator-servicecomb-java-chassis/pom.xml`, and add `<module>samples</module>` to `<modules></modules>` block, Then find `main` function `CodeFirstProviderMain` of provider service and `RUN` it like any other Java program.

3. Start the codefirst-consumer service

```bash
cd samples/codefirst-sample/codefirst-consumer/
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain"
```

- Start consumer service via maven

Just like how to start codefirst-provider service. But the main class of codefirst-consumer service is `CodeFirstConsumerMain`.

```bash
mvn exec:java -Dexec.mainClass="org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain"
```

- Start consumer service via gradle

```bash
gradle clean run
```

4. How to verify
On the producer side, the output should contain the following stuffs if the producer starts up successfully:
1. *'swagger: 2.0 info: version: 1.0.0 ...'* means the producer generated swagger contracts
Expand Down
39 changes: 39 additions & 0 deletions samples/codefirst-sample/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

allprojects {
apply plugin: 'maven'

group = 'org.apache.servicecomb.samples'
version = '1.0.0-m2-SNAPSHOT'
}

subprojects {
apply plugin: 'java'

sourceCompatibility = 1.8
targetCompatibility = 1.8

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenLocal()
mavenCentral()
}
}
51 changes: 51 additions & 0 deletions samples/codefirst-sample/codefirst-consumer/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

description = 'Java Chassis::Samples::CodeFirst::Consumer'

dependencies {
compile group: 'org.apache.servicecomb', name: 'provider-pojo'
compile group: 'org.apache.servicecomb', name: 'transport-highway'
compile group: 'org.apache.servicecomb', name: 'transport-rest-vertx'
compile group: 'org.apache.servicecomb.samples', name: 'common-schema', version: '1.0.0-m2-SNAPSHOT'
compile group: 'org.slf4j', name: 'slf4j-log4j12'
}

apply plugin: 'application'

mainClassName = 'org.apache.servicecomb.samples.codefirst.consumer.CodeFirstConsumerMain'

// dependency-management-plugin is a replacement of dependencyManagement in maven
// we need to enable the plugin and specify the dependencyManagement in the following form in each submodule
// according to the official document: https://github.com/spring-gradle-plugins/dependency-management-plugin.
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath('io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE')
}
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
imports {
mavenBom 'org.apache.servicecomb:java-chassis-dependencies:1.0.0-m2-SNAPSHOT'
}
}
Loading