-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
102 lines (83 loc) · 3.15 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Apply the plugin allows you to make java executable tasks
apply plugin: 'java'
// Apply the plugin allows you to set the java version used to compile the project
apply plugin: 'java-library'
// Set the description of the gradle project
description = "Client Server Socket Example"
// Set the java version of the gradle project
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(18))
}
}
// Set the gradle wrapper version
// to use a specific version of gradle
wrapper {
// Set the gradle version
gradleVersion = '7.4.2'
// Allow all types of installations of gradle distributions
distributionType = Wrapper.DistributionType.ALL
}
// Set the repositories to download the dependencies
repositories {
// Set the maven central repository to download the dependencies
// The link to the maven central repository is https://repo1.maven.org/maven2/
mavenCentral()
}
// Set the dependencies of the project
dependencies {
// Implement gson
// The link to the gson library is
// https://mvnrepository.com/artifact/com.google.code.gson/gson
implementation group: 'com.google.code.gson', name: 'gson', version: '2.10.1'
}
// Tell the IDEA and also java gradle plugin
// to mark the src folder as the source folder
// and the resources folder as the resources folder
sourceSets {
src {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
}
}
// Client and Server socket
// This task will run the Server capable of handling multiple clients
task Server(type: JavaExec) {
group 'TCP Server/Client'
description 'Creates Server socket that awaits for new clients to connect'
// Set the classpath to the the above source sets
classpath = sourceSets.main.runtimeClasspath
// Set the main Class relative to the java source files.
main = 'server.SockServer'
// Set standard input to be the terminal
standardInput = System.in
// Get the port number from the project properties or use the default port 8888
String port = (project.hasProperty("port") ? project.property("port") : "8888")
// Pass the port to the java arguments
args port
}
// This task will run the Client
// It will connect to the server and send a message
// The server will respond with a message
task Client(type: JavaExec) {
group 'TCP Server/Client'
description 'Creates Client socket that connects to the server'
// Set the classpath to the the above source sets
classpath = sourceSets.main.runtimeClasspath
// Set the main Class relative to the java source files.
main = 'client.SockClient'
// Set standard input to be the terminal
standardInput = System.in
// Get the port number from the project properties or use the default port 8888
String port = (project.hasProperty("port") ? project.property("port") : "8888")
// Get the host from the project properties or use the default host
String host = (project.hasProperty("host") ? project.property("host") : "localhost")
// Pass the port and host to the java arguments
args port, host
}