Issue
I would like to use https://github.com/fmmfonseca/completely in an Android project and as far as I can tell that means it should be compiled to target JDK 1.8
I am using Netbeans 11 and I have set the target to 1.8
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<artifactId>completely</artifactId>
<groupId>com.miguelfonseca.completely</groupId>
<version>0.9.0</version>
</parent>
<artifactId>completely-core</artifactId>
<name>completely-core</name>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
<repositories>
<repository>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
and yet when I compile and check the newly created .class files, eg.
AutoCompleteLibrary\core\target\classes\com\miguelfonseca\completely\AutocompleteEngine.class
I see in hex
CA FE BA BE 00 00 00 37
the 37
means the class file is compiled to language level 55
or JDK 11.
I have tried every way possible to set the target JDK in the pom but nothing works.
Here's the Maven (v3) log. Which I notice has <release>11</release>
in it, not sure why.
=== PROJECT BUILD PLAN ================================================
Project: com.miguelfonseca.completely:completely-core:0.9.0
Dependencies (collect): []
Dependencies (resolve): [compile, runtime, test]
Repositories (dependencies): [central (https://repo.maven.apache.org/maven2, default, releases)]
Repositories (plugins) : [central (https://repo.maven.apache.org/maven2, default, releases)]
-----------------------------------------------------------------------
Goal: org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean)
Style: Regular
Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<directory default-value="${project.build.directory}"/>
<excludeDefaultDirectories default-value="false">${clean.excludeDefaultDirectories}</excludeDefaultDirectories>
<failOnError default-value="true">${maven.clean.failOnError}</failOnError>
<followSymLinks default-value="false">${clean.followSymLinks}</followSymLinks>
<outputDirectory default-value="${project.build.outputDirectory}"/>
<reportDirectory default-value="${project.reporting.outputDirectory}"/>
<retryOnError default-value="true">${maven.clean.retryOnError}</retryOnError>
<skip default-value="false">${clean.skip}</skip>
<testOutputDirectory default-value="${project.build.testOutputDirectory}"/>
<verbose>${clean.verbose}</verbose>
</configuration>
-----------------------------------------------------------------------
Goal: org.jacoco:jacoco-maven-plugin:0.8.5:prepare-agent (default)
Style: Regular
Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<address>${jacoco.address}</address>
<append>${jacoco.append}</append>
<classDumpDir>${jacoco.classDumpDir}</classDumpDir>
<destFile default-value="${project.build.directory}/jacoco.exec">${jacoco.destFile}</destFile>
<dumpOnExit>${jacoco.dumpOnExit}</dumpOnExit>
<exclClassLoaders>${jacoco.exclClassLoaders}</exclClassLoaders>
<inclBootstrapClasses>${jacoco.inclBootstrapClasses}</inclBootstrapClasses>
<inclNoLocationClasses>${jacoco.inclNoLocationClasses}</inclNoLocationClasses>
<jmx>${jacoco.jmx}</jmx>
<output>${jacoco.output}</output>
<pluginArtifactMap>${plugin.artifactMap}</pluginArtifactMap>
<port>${jacoco.port}</port>
<project>${project}</project>
<propertyName>${jacoco.propertyName}</propertyName>
<sessionId>${jacoco.sessionId}</sessionId>
<skip default-value="false">${jacoco.skip}</skip>
</configuration>
-----------------------------------------------------------------------
Goal: org.apache.maven.plugins:maven-resources-plugin:2.6:resources (default-resources)
Style: Regular
Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<buildFilters default-value="${project.build.filters}"/>
<encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<escapeString>${maven.resources.escapeString}</escapeString>
<escapeWindowsPaths default-value="true">${maven.resources.escapeWindowsPaths}</escapeWindowsPaths>
<includeEmptyDirs default-value="false">${maven.resources.includeEmptyDirs}</includeEmptyDirs>
<outputDirectory default-value="${project.build.outputDirectory}"/>
<overwrite default-value="false">${maven.resources.overwrite}</overwrite>
<project default-value="${project}"/>
<resources default-value="${project.resources}"/>
<session default-value="${session}"/>
<supportMultiLineFiltering default-value="false">${maven.resources.supportMultiLineFiltering}</supportMultiLineFiltering>
<useBuildFilters default-value="true"/>
<useDefaultDelimiters default-value="true"/>
</configuration>
-----------------------------------------------------------------------
Goal: org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile)
Style: Regular
Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<basedir default-value="${basedir}"/>
<buildDirectory default-value="${project.build.directory}"/>
<compilePath default-value="${project.compileClasspathElements}"/>
<compileSourceRoots default-value="${project.compileSourceRoots}"/>
<compilerArgs>
<arg>-Xlint</arg>
</compilerArgs>
<compilerId default-value="javac">${maven.compiler.compilerId}</compilerId>
<compilerReuseStrategy default-value="${reuseCreated}">${maven.compiler.compilerReuseStrategy}</compilerReuseStrategy>
<compilerVersion>${maven.compiler.compilerVersion}</compilerVersion>
<debug default-value="true">${maven.compiler.debug}</debug>
<debuglevel>${maven.compiler.debuglevel}</debuglevel>
<encoding default-value="${project.build.sourceEncoding}">${encoding}</encoding>
<executable>${maven.compiler.executable}</executable>
<failOnError default-value="true">${maven.compiler.failOnError}</failOnError>
<failOnWarning default-value="false">${maven.compiler.failOnWarning}</failOnWarning>
<forceJavacCompilerUse default-value="false">${maven.compiler.forceJavacCompilerUse}</forceJavacCompilerUse>
<fork default-value="false">${maven.compiler.fork}</fork>
<generatedSourcesDirectory default-value="${project.build.directory}/generated-sources/annotations"/>
<maxmem>${maven.compiler.maxmem}</maxmem>
<meminitial>${maven.compiler.meminitial}</meminitial>
<mojoExecution default-value="${mojoExecution}"/>
<optimize default-value="false">${maven.compiler.optimize}</optimize>
<outputDirectory default-value="${project.build.outputDirectory}"/>
<parameters default-value="false">${maven.compiler.parameters}</parameters>
<project default-value="${project}"/>
<projectArtifact default-value="${project.artifact}"/>
<release>11</release>
<session default-value="${session}"/>
<showDeprecation default-value="false">${maven.compiler.showDeprecation}</showDeprecation>
<showWarnings default-value="false">${maven.compiler.showWarnings}</showWarnings>
<skipMain>${maven.main.skip}</skipMain>
<skipMultiThreadWarning default-value="false">${maven.compiler.skipMultiThreadWarning}</skipMultiThreadWarning>
<source default-value="1.6">${maven.compiler.source}</source>
<staleMillis default-value="0">${lastModGranularityMs}</staleMillis>
<target default-value="1.6">${maven.compiler.target}</target>
<useIncrementalCompilation default-value="true">${maven.compiler.useIncrementalCompilation}</useIncrementalCompilation>
<verbose default-value="false">${maven.compiler.verbose}</verbose>
</configuration>
....
--- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ completely-core ---
Configuring mojo org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile from plugin realm ClassRealm[plugin>org.apache.maven.plugins:maven-compiler-plugin:3.8.1, parent: jdk.internal.loader.ClassLoaders$AppClassLoader@c387f44]
Configuring mojo 'org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile' with basic configurator -->
(f) basedir = c:\AutoCompleteLibrary\core
(f) buildDirectory = c:\AutoCompleteLibrary\core\target
(f) compilePath = [c:\AutoCompleteLibrary\core\target\classes, C:\Users\jdlwr\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar]
(f) compileSourceRoots = [c:\AutoCompleteLibrary\core\src\test\java]
(f) compilerArgs = [-Xlint]
(f) compilerId = javac
(f) debug = true
(f) encoding = utf-8
(f) failOnError = true
(f) failOnWarning = false
(f) forceJavacCompilerUse = false
(f) fork = false
(f) generatedTestSourcesDirectory = c:\AutoCompleteLibrary\core\target\generated-test-sources\test-annotations
(f) mojoExecution = org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile {execution: default-testCompile}
(f) optimize = false
(f) outputDirectory = c:\AutoCompleteLibrary\core\target\test-classes
(f) parameters = false
(f) project = MavenProject: com.miguelfonseca.completely:completely-core:0.9.0 @ c:\AutoCompleteLibrary\core\pom.xml
(s) release = 11
(f) session = org.apache.maven.execution.MavenSession@2e3f79a2
(f) showDeprecation = false
(f) showWarnings = false
(f) skipMultiThreadWarning = false
(f) source = 1.8
(f) staleMillis = 0
(s) target = 1.8
(f) testPath = [c:\AutoCompleteLibrary\core\target\test-classes, c:\AutoCompleteLibrary\core\target\classes, C:\Users\jdlwr\.m2\repository\org\junit\jupiter\junit-jupiter\5.6.2\junit-jupiter-5.6.2.jar, C:\Users\jdlwr\.m2\repository\org\junit\jupiter\junit-jupiter-api\5.6.2\junit-jupiter-api-5.6.2.jar, C:\Users\jdlwr\.m2\repository\org\apiguardian\apiguardian-api\1.1.0\apiguardian-api-1.1.0.jar, C:\Users\jdlwr\.m2\repository\org\opentest4j\opentest4j\1.2.0\opentest4j-1.2.0.jar, C:\Users\jdlwr\.m2\repository\org\junit\platform\junit-platform-commons\1.6.2\junit-platform-commons-1.6.2.jar, C:\Users\jdlwr\.m2\repository\org\junit\jupiter\junit-jupiter-params\5.6.2\junit-jupiter-params-5.6.2.jar, C:\Users\jdlwr\.m2\repository\org\junit\jupiter\junit-jupiter-engine\5.6.2\junit-jupiter-engine-5.6.2.jar, C:\Users\jdlwr\.m2\repository\org\junit\platform\junit-platform-engine\1.6.2\junit-platform-engine-1.6.2.jar, C:\Users\jdlwr\.m2\repository\com\google\code\findbugs\jsr305\3.0.2\jsr305-3.0.2.jar]
(f) useIncrementalCompilation = true
(f) verbose = false
The thing I don't understand in the last part is that it has both
(s) release = 11
(s) target = 1.8
Solution
The setting for <release>11</release>
is coming from your parent POM:
https://search.maven.org/artifact/com.miguelfonseca.completely/completely/0.9.0/pom
I guess that it takes precedence over your source and target settings. Try to override the release
configuration.
Answered By - J Fabian Meier