- Building Serverless Architectures
- Cagatay Gurturk
- 577字
- 2021-07-02 19:04:43
Creating the project
Finally, we can start creating our project. We will create our project in our home directory, so we can start with these commands:
$ mkdir -p ~ /serverlessbook $ cd ~/serverlessbook
Once we create the working directory, we can create the build.gradle file, which will be the main build file of our project:
$ touch build.gradle
We can start with the Gradle wrapper task, which will generate Gradle files in our project. Write this block into the build.gradle file:
task wrapper(type: Wrapper) { gradleVersion = '2.14' }
And then execute the command:
$ gradle wrapper
This will create Gradle wrapper files in our project. This means that in the root directory of the project, ./gradlew can be called instead of the local gradle. It is a nice feature of Gradle: Let's assume that you distributed your project to other team members and you are not sure whether they have Gradle installed on their system (or its version if they already have). With the Gradle wrapper, you make sure that everybody who checked out the project will run Gradle 2.14 if they run ./gradlew. If they do not have any Gradle version in their system, the script will download it.
We can now proceed to add the declarations needed for all projects. Add this code block to the build.gradle file:
// allprojects means this configuration // will be inherited by the root project itself and subprojects allprojects { // Artifact Id of the projct group 'com.serverlessbook' // Version of the project version '1.0' // Gradle JAVA plugin needed for JAVA support apply plugin: 'java' // We will be using JAVA 8, then 1.8 sourceCompatibility = 1.8 }
With this code block, we tell to Gradle that we are building a Java 8 project with the artifact ID com.serverlessbook and version 1.0.
Also, we need to create the settings.gradle file, which will include some generic settings about the project and subproject names in the future. In the root project, create a new file with the name settings.gradle and type this line:
rootProject.name = 'forum'
Actually, this line is optional. When the root project name is not given a name explicitly, Gradle assigns the name of the directory where the project is placed as the project name. For consistency, however, it is a good idea to name the project explicitly because other developers may always check out our code to a directory with another name and we would not love that our project has another name then.
Now we should add repositories to fetch the dependencies for the project itself and the build script. In order to accomplish this, first, we have to add this block to the build.gradle file:
allprojects {
repositories {
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}
}
Here, we defined Maven Central, Bintray JCenter, and Jitpack as the three most popular repositories. We need the same dependencies for the build script, thus we add the following block to the same file:
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
url "https://jitpack.io"
}
}
}
- DB2 V9權威指南
- jQuery Mobile Web Development Essentials(Third Edition)
- R語言數據分析從入門到精通
- Power Up Your PowToon Studio Project
- Instant Zepto.js
- 人臉識別原理及算法:動態人臉識別系統研究
- Mastering Kali Linux for Web Penetration Testing
- Learning SciPy for Numerical and Scientific Computing(Second Edition)
- NGINX Cookbook
- OpenGL Data Visualization Cookbook
- 創意UI:Photoshop玩轉APP設計
- Java 9 Programming By Example
- Android移動應用開發項目教程
- DB2SQL性能調優秘笈
- Microsoft XNA 4.0 Game Development Cookbook