Skip to content

Commit d300511

Browse files
committed
Allow to not use --module-version for the Java compiler
1 parent 5dbc9c3 commit d300511

File tree

6 files changed

+145
-3
lines changed

6 files changed

+145
-3
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
invoker.java.version = 9+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
25+
<groupId>org.apache.maven.plugins.compiler.it</groupId>
26+
<artifactId>GH-331-no-module-version</artifactId>
27+
<version>1.0-SNAPSHOT</version>
28+
29+
<url>https://github.com/apache/maven-compiler-plugin/pull/331</url>
30+
31+
<properties>
32+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
33+
<maven.compiler.release>9</maven.compiler.release>
34+
<maven.compiler.useModuleVersion>false</maven.compiler.useModuleVersion>
35+
</properties>
36+
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<artifactId>maven-compiler-plugin</artifactId>
41+
<version>@project.version@</version>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.foo;
20+
21+
public class MyClass {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
module M.N {
21+
exports com.foo;
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
def log = new File(basedir, 'build.log').text
20+
21+
assert log.count(' --module-version') == 0
22+
23+
def descriptor = java.lang.module.ModuleFinder.of(basedir.toPath().resolve('target/classes')).find('M.N').get().descriptor()
24+
assert descriptor.version().empty
25+
assert 'M.N' == descriptor.toNameAndVersion()

src/main/java/org/apache/maven/plugin/compiler/CompilerMojo.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ public class CompilerMojo extends AbstractCompilerMojo {
172172
@Parameter(property = "maven.compiler.moduleVersion", defaultValue = "${project.version}")
173173
private String moduleVersion;
174174

175+
/**
176+
* Use the {@code --module-version} argument for the Java compiler.
177+
* This is ignored if not applicable, e.g., in non-modular projects.
178+
*
179+
* @see <a href="https://docs.oracle.com/en/java/javase/17/docs/specs/man/javac.html#option-module-version">javac --module-version</a>
180+
* @since 3.15.0
181+
*/
182+
@Parameter(property = "maven.compiler.useModuleVersion", defaultValue = "true")
183+
private boolean useModuleVersion;
184+
175185
final LocationManager locationManager = new LocationManager();
176186

177187
private List<String> classpathElements;
@@ -311,9 +321,10 @@ protected void preparePaths(Set<File> sourceFiles) {
311321
modulepathElements.add(file.getPath());
312322
}
313323

314-
compilerArgs.add("--module-version");
315-
compilerArgs.add(moduleVersion);
316-
324+
if (useModuleVersion) {
325+
compilerArgs.add("--module-version");
326+
compilerArgs.add(moduleVersion);
327+
}
317328
} catch (IOException e) {
318329
getLog().warn(e.getMessage());
319330
}

0 commit comments

Comments
 (0)