Skip to content

Commit a170429

Browse files
authored
Update standalone module to work with standard build (#49)
* Update gradle build scripts of standalone module for 21.3 * Use `settings.gradle` to configure standalone gradle project * Use LabKey gradle plugins by default. Move noPlugin build to a separate file
1 parent ed03b9a commit a170429

File tree

11 files changed

+292
-270
lines changed

11 files changed

+292
-270
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
demo/node_modules
33
demo/resources/web/demo/gen
44
demo/resources/views/gen
5+
dependencies.txt
6+
enlistment.properties
7+
build/
58

69
# Gradle
710
.gradle

standalone/build.gradle

Lines changed: 9 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,31 @@
11
// This is a sample gradle file for creating a stand-alone Java module that can be deployed in a LabKey server
2-
// instance. This file assumes the module layout described in the LabKey documentation
2+
// instance. This file applies some of the LabKey Gradle plugins and thus assumes the module layout described
3+
// in the LabKey documentation
34
// (https://labkey.org/Documentation/wiki-page.view?name=moduleDirectoryStructures)
4-
// but, for simplicity, does not include JSP files that would be compiled and collected into a JSP jar file
5+
// For simplicity, the source code does not include JSP files that would be compiled and collected into a JSP jar file
56
// or XSD files that would be transformed into XMLBeans objects and include in the main jar.
67
//
78
// You can refer to the gradlePlugins source code (https://github.com/LabKey/gradlePlugin) for more details on the
89
// full build process implemented for modules within the LabKey source tree.
910
//
10-
// Also for simplicity, this example deliberately does not use the LabKey Gradle plugins, but if your module
11-
// has JSPs or other client-side code and XMLBeans you may want to consider using these plugins. You will
12-
// need to add a dependency on the plugins (see the settings.gradle file in LabKey Server's root enlistment)
13-
// and then apply the appropriate plugins, probably most simply the 'org.labkey.module' plugin, which, in turn,
14-
// will apply, for example, the JSP and NpmRun plugins, among others.
15-
//
16-
// Then run the command
11+
// To build this module, run:
1712
// ./gradlew module
1813
// This will create a .module file for your project and deposit it in the build directory
1914
// for your standalone module.
2015
//
2116
// See the Gradle documentation for more information (https://docs.gradle.org).
2217
//
23-
import java.util.regex.Matcher
24-
import java.util.regex.Pattern
25-
26-
apply plugin: 'java'
18+
import org.labkey.gradle.util.BuildUtils
2719

28-
project.version="20.7-SNAPSHOT"
29-
30-
ext {
31-
// The following are convenience variables for the various output directories used below
32-
explodedModuleDir = "${project.buildDir}/explodedModule"
33-
libDir = "${explodedModuleDir}/lib"
34-
configDir = "${explodedModuleDir}/config"
20+
plugins {
21+
// This plugin brings in the standard tasks for building a LabKey Java module that may include JSPs, XSDs, or npm builds
22+
id 'org.labkey.build.module'
3523
}
3624

37-
repositories
38-
{
39-
// Use this repository when relying on release versions of the LabKey artifacts and their external dependencies
40-
maven {
41-
url "${project.artifactoryContextUrl}/libs-release"
42-
}
43-
// Use this repository when relying on snapshot versions of LabKey artifacts or requiring snapshot external dependencies
44-
maven {
45-
url "${project.artifactoryContextUrl}/libs-snapshot"
46-
}
47-
jcenter() // include the bintray/jcenter repository separately in case lookup with previous repository fails
48-
}
49-
50-
configurations
51-
{
52-
external // Define a configuration for use in specifying which libraries should be included in the module's lib directory
53-
implementation.extendsFrom(external)
54-
}
25+
project.version="0.0.1-SNAPSHOT" // this can use your own versioning scheme
5526

5627
dependencies
5728
{
58-
implementation "org.labkey.api:internal:${labkeyVersion}" // Dependency on the api jar file for internal module
5929
implementation "org.labkey.api:issues:${labkeyVersion}" // An example of declaring a dependency on the API jar for a module
60-
implementation "org.labkey.api:labkey-client-api:${labkeyClientApiVersion}" // Dependency on the LabKey client api
6130
external "commons-beanutils:commons-beanutils:${commonsBeanutilsVersion}" // An external dependency to be included in the module's lib directory
62-
}
63-
64-
65-
project.sourceSets
66-
{
67-
main { // source files for the main Jar file
68-
java {
69-
srcDirs = ['src']
70-
}
71-
}
72-
module {
73-
resources { // resources to be included in the module Jar file
74-
srcDirs = ['resources']
75-
}
76-
output.resourcesDir = explodedModuleDir
77-
}
78-
api { // source files for the api Jar file
79-
java {
80-
srcDirs = ['api-src']
81-
}
82-
}
83-
// use this if you have a spring configuration file in your project
84-
spring {
85-
resources {
86-
srcDirs = ["webapp/WEB-INF"]
87-
}
88-
output.resourcesDir = configDir
89-
}
9031
}
91-
92-
project.tasks.register("apiJar", Jar) {
93-
Jar jar ->
94-
jar.group = "Build"
95-
jar.description = "produce jar file for api"
96-
jar.from project.sourceSets.api.output
97-
jar.archiveBaseName.set("${project.name}_api")
98-
jar.destinationDirectory = project.file(libDir)
99-
jar.dependsOn(project.apiClasses)
100-
}
101-
102-
project.jar {
103-
Jar jar ->
104-
jar.archiveBaseName.set(project.name)
105-
jar.destinationDirectory = project.file(libDir)
106-
jar.dependsOn(project.tasks.apiJar)
107-
}
108-
109-
project.tasks.register("copyExternalLibs", Copy) {
110-
CopySpec copy ->
111-
copy.group = "Build"
112-
copy.description = "copy the dependencies declared in the 'external' configuration into the lib directory of the built module"
113-
copy.from project.configurations.external
114-
copy.into libDir
115-
}
116-
117-
project.tasks.register('moduleXml') {
118-
Task task ->
119-
task.group = "Build"
120-
task.description = "Create the module.xml file from the module.properties and module.template.xml files"
121-
task.inputs.file(project.file("module.template.xml"))
122-
task.inputs.file(project.file("module.properties"))
123-
task.outputs.file(new File(configDir.toString(), "module.xml"))
124-
task.doLast
125-
{
126-
final Pattern PROPERTY_PATTERN = Pattern.compile("@@([^@]+)@@")
127-
128-
Properties modProperties = new Properties()
129-
FileInputStream propertiesStream = new FileInputStream("module.properties")
130-
modProperties.load(propertiesStream)
131-
propertiesStream.close()
132-
133-
InputStream is = new FileInputStream(new File("module.template.xml"))
134-
135-
if (is == null) {
136-
throw new GradleException("Could not find template file 'module.template.xml'.")
137-
}
138-
139-
project.mkdir(configDir)
140-
File moduleXmlFile = new File((String) configDir, "module.xml")
141-
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(moduleXmlFile))
142-
143-
is.readLines().each {
144-
String line ->
145-
Matcher matcher = PROPERTY_PATTERN.matcher(line)
146-
String newLine = line
147-
while (matcher.find()) {
148-
String property = (String) modProperties.get(matcher.group(1))
149-
newLine = newLine.replace(matcher.group(), property == null ? "" : property)
150-
}
151-
writer.println(newLine)
152-
}
153-
writer.close()
154-
is.close()
155-
}
156-
157-
}
158-
159-
project.tasks.register("module", Jar) {
160-
Jar jar ->
161-
jar.group = "Build"
162-
jar.description = "create the module file for this project"
163-
jar.from explodedModuleDir
164-
jar.archiveBaseName.set(project.name)
165-
jar.archiveExtension.set('module')
166-
jar.destinationDirectory = project.buildDir
167-
jar.dependsOn(project.tasks.moduleXml)
168-
jar.dependsOn(project.tasks.processModuleResources)
169-
jar.dependsOn(project.tasks.copyExternalLibs)
170-
jar.dependsOn(project.tasks.jar)
171-
jar.dependsOn(project.tasks.processSpringResources)
172-
}
173-

standalone/gradle.properties

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# Location of the repository for various artifacts used in the build
2-
artifactoryContextUrl=https://artifactory.labkey.com/artifactory
2+
artifactory_contextUrl=https://artifactory.labkey.com/artifactory
33

44
# Version 1.17.0 or higher is required to fully support building stand-alone modules with the LabKey Gradle plugins
5-
gradlePluginsVersion=1.17.0
5+
# Exact version will vary based on the version of LabKey being built on
6+
gradlePluginsVersion=1.27.0_standaloneBuild-SNAPSHOT
67

78
# versions of artifacts required as dependencies
8-
labkeyVersion=20.7.0
9-
labkeyClientApiVersion=1.3.0
9+
labkeyVersion=21.3.4
10+
labkeyClientApiVersion=1.3.2
1011

1112
# used by the LabKey Jsp Gradle plugin for declaring dependencies
1213
apacheTomcatVersion=8.5.51
4.87 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Sun Jun 04 20:22:05 PDT 2017
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip

standalone/gradlew

Lines changed: 36 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)