Add check for headless when getting the number of displays.
[SquirrelJME.git] / build.gradle
blob0c5205a437790122352c75ee4ef60e681b2e74ab
1 import java.nio.file.Files
2 import java.nio.file.StandardOpenOption
4 apply plugin: 'idea'
5 apply plugin: 'eclipse'
6 apply plugin: 'cc.squirreljme.plugin.general'
8 group = "cc.squirreljme"
9 description = "SquirrelJME is a Java ME 8 Virtual Machine for embedded " +
10         "and Internet of Things devices. It has the ultimate goal of being " +
11         "99.9% compatible with the Java ME standard."
12 version = squirreljmeVersion
14 // IntelliJ Configuration (because the root project is a bit different)
15 idea
17         module
18         {
19                 // Use the proper name for this module
20                 name = "SquirrelJME"
22                 // Exclude these directories so IntelliJ does not pick these up
23                 // in inspections and builds
24                 excludeDirs += file(".circleci")
25                 excludeDirs += file(".fossil-settings")
26                 excludeDirs += file(".github")
27                 excludeDirs += file(".idea")
28                 excludeDirs += file(".vscode")
29                 excludeDirs += file(".settings")
30                 excludeDirs += file("assets")
31                 excludeDirs += file("config")
32                 excludeDirs += file("gradle")
33                 excludeDirs += file("utils-dev")
34                 
35                 // These are auto-generated by Fossil and should be ignored
36                 excludeDirs += file("manifest")
37                 excludeDirs += file("manifest.uuid")
38                 
39                 // RatufaCoat files
40                 excludeDirs += file("ratufacoat/build")
41                 excludeDirs += file("ratufacoat/cmake-build-debug")
42                 excludeDirs += file("ratufacoat/cmake-build-release")
43                 excludeDirs += file("ratufacoat/.sample")
44                 
45                 // IntelliJ's own dependency matrix output (in "out")
46                 project.allprojects.each() { Project subProj ->
47                         excludeDirs += subProj.projectDir.toPath().resolve("out").toFile()
48                         
49                         // Eclipse Junk
50                         excludeDirs += subProj.projectDir.toPath().resolve(".settings").toFile()
51                         excludeDirs += subProj.projectDir.toPath().resolve("bin").toFile()
52                 }
53         }
56 allprojects {
57         apply plugin: 'eclipse'
58         
59         repositories
60         {
61                 mavenCentral()
62         }
63         
64         // Eclipse IDE
65         plugins.withType(JavaPlugin) {
66                 def settingsDir = projectDir.toPath().resolve(".settings")
67                 def buildShipPrefs = settingsDir.resolve("org.eclipse.buildship.core.prefs")
68                 def pathToRoot = projectDir.toPath().relativize(rootDir.toPath())
69                 
70                 // Clean fix
71                 task cleanEclipseFixBuild {
72                         group "squirreljme"
73                         description "Cleans up after build fixes."
74                         
75                         doFirst {
76                                 // Just delete the buildship preferences
77                                 Files.deleteIfExists(buildShipPrefs)
78                         }
79                 }
80                 
81                 // Fix build
82                 task eclipseFixBuild {
83                         group "squirreljme"
84                         description "Fixes Eclipse build due to missing expected files."
85                         
86                         // If clean and such is ran, this must always be followed by it
87                         // since we could accidentally destroy it
88                         mustRunAfter cleanEclipseFixBuild, cleanEclipseJdt
89                         
90                         doFirst {
91                                 // Setup settings directory first
92                                 Files.createDirectories(settingsDir)
93                                 
94                                 // Write missing Eclipse file
95                                 Files.write(
96                                         buildShipPrefs,
97                                         Arrays.asList(
98                                                 "connection.project.dir=" + pathToRoot,
99                                                 "eclipse.preferences.version=1"),
100                                         StandardOpenOption.CREATE,
101                                         StandardOpenOption.WRITE,
102                                         StandardOpenOption.TRUNCATE_EXISTING)
103                         }
104                 }
105                 
106                 // Fix for cyclic dependencies
107                 eclipse.jdt {
108                         // We are a Java 8 project
109                         sourceCompatibility = 1.8
110                         targetCompatibility = 1.8
111                         
112                         // Fix for Eclipse and VSCode breaking on "circular" dependencies
113                         file.withProperties { properties ->
114                                 properties["org.eclipse.jdt.core.builder.invalidClasspath"] = "warning"
115                                 properties["org.eclipse.jdt.core.circularClasspath"] = "warning"
116                                 properties["org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource"] = "warning"
117                         }
118                 }
119                 
120                 eclipseJdt.finalizedBy(eclipseFixBuild)
121                 cleanEclipseJdt.finalizedBy(cleanEclipseFixBuild)
122         }