Skip to content

Commit 7a10214

Browse files
Set mainClass as optional, fix samples to be usable standalone
Before this commit if mainClass was missing, Gradle plugin would abort the build. This is wrong since mainClass isn't required for building shared libraries (also, mainClass can be defined using properties file). This change fixes #108 Second change that is introduced in this commit fixes issue #105
1 parent d1695ef commit 7a10214

File tree

24 files changed

+174
-10
lines changed

24 files changed

+174
-10
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ tasks.register<Zip>("releaseZip") {
8888

8989
tasks.register<org.graalvm.build.samples.SamplesUpdateTask>("updateSamples") {
9090
inputDirectory.set(layout.projectDirectory.dir("samples"))
91+
versions.put("native.gradle.plugin.version", libs.versions.nativeGradlePlugin.get())
9192
versions.put("native.maven.plugin.version", libs.versions.nativeMavenPlugin.get())
9293
versions.put("junit.jupiter.version", libs.versions.junitJupiter.get())
9394
versions.put("junit.platform.version", libs.versions.junitPlatform.get())

native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/JavaApplicationWithAgentFunctionalTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractFunctionalTest {
9393
@Unroll("agent property takes precedence on Gradle #version with JUnit Platform #junitVersion")
9494
def "agent property takes precedence"() {
9595
gradleVersion = version
96-
96+
9797
given:
9898
withSample("java-application-with-reflection")
9999

native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/KotlinApplicationWithTestsFunctionalTest.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class KotlinApplicationWithTestsFunctionalTest extends AbstractFunctionalTest {
5050
@Unroll("can execute Kotlin tests in a native image directly on Gradle #version with JUnit Platform #junitVersion")
5151
def "can execute Kotlin tests in a native image directly"() {
5252
gradleVersion = version
53-
53+
5454
given:
5555
withSample("kotlin-application-with-tests")
5656

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
import org.gradle.api.tasks.Input;
5656
import org.gradle.api.tasks.InputFiles;
5757
import org.gradle.api.tasks.Nested;
58+
import org.gradle.api.tasks.Optional;
5859
import org.gradle.jvm.toolchain.JavaLanguageVersion;
5960
import org.gradle.jvm.toolchain.JavaLauncher;
6061
import org.gradle.jvm.toolchain.JavaToolchainService;
@@ -91,6 +92,7 @@ public abstract class NativeImageOptions {
9192
* @return mainClass The main class.
9293
*/
9394
@Input
95+
@Optional
9496
public abstract Property<String> getMainClass();
9597

9698
/**

samples/java-application-with-reflection/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ plugins {
4646

4747
repositories {
4848
mavenCentral()
49+
mavenLocal()
4950
}
5051

5152
application {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
junit.platform.native.version = 0.9.3-SNAPSHOT
1+
native.gradle.plugin.version = 0.9.3-SNAPSHOT
22
junit.jupiter.version = 5.7.2
33
junit.platform.version = 1.7.2

samples/java-application-with-reflection/settings.gradle

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@
3939
* SOFTWARE.
4040
*/
4141

42+
pluginManagement {
43+
plugins {
44+
id 'org.graalvm.buildtools.native' version getProperty('native.gradle.plugin.version')
45+
}
46+
repositories {
47+
mavenCentral()
48+
gradlePluginPortal()
49+
mavenLocal()
50+
}
51+
}
52+
4253
rootProject.name = 'java-application'

samples/java-application-with-resources/build.gradle

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,54 @@
1+
/*
2+
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
142
plugins {
243
id 'application'
344
id 'org.graalvm.buildtools.native'
445
}
546

47+
repositories {
48+
mavenCentral()
49+
mavenLocal()
50+
}
51+
652
application {
753
mainClass.set('org.graalvm.demo.Application')
854
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
junit.platform.native.version = 0.9.2-SNAPSHOT
1+
native.gradle.plugin.version = 0.9.3-SNAPSHOT
22
junit.jupiter.version = 5.7.2
33
junit.platform.version = 1.7.2

samples/java-application-with-resources/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
<properties>
5252
<java.version>1.8</java.version>
5353
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
54-
<native.maven.plugin.version>0.9.2-SNAPSHOT</native.maven.plugin.version>
55-
<junit.platform.native.version>0.9.2-SNAPSHOT</junit.platform.native.version>
54+
<native.maven.plugin.version>0.9.3-SNAPSHOT</native.maven.plugin.version>
55+
<junit.platform.native.version>0.9.3-SNAPSHOT</junit.platform.native.version>
5656
<imageName>example-app</imageName>
5757
<mainClass>org.graalvm.demo.Application</mainClass>
5858
</properties>

0 commit comments

Comments
 (0)