ProGuard says Unsupported class version number [52.0] (maximum 51.0, Java 1.7) with sbt-proguard - sbt

I'm on Mac OS X 10.9.2 and sbt 0.13.3-SNAPSHOT (built from the sources), Java 8 and sbt-proguard 0.2.2 plugin.
sbt 0.13.3-SNAPSHOT
[jacek]> sbtVersion
[info] 0.13.3-SNAPSHOT
Java 8
$ /Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/bin/java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
project/plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")
When I ran proguard:proguard in sbt shell it blew up with the following exception:
[sbt-updates]> show proguard:proguard
[info] ProGuard, version 4.9
[info] Reading program directory [/Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-concurrent_2.10/bundles/scalaz-concurrent_2.10-7.1.0-M6.jar] (filtered)
[info] Reading program jar [/Users/jacek/.sbt/boot/scala-2.10.3/lib/scala-library.jar] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-core_2.10/bundles/scalaz-core_2.10-7.1.0-M6.jar] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-effect_2.10/bundles/scalaz-effect_2.10-7.1.0-M6.jar] (filtered)
[info] Reading library jar [/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar]
[error] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.8.0.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [apple/applescript/AppleScriptEngine.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
[trace] Stack trace suppressed: run last proguard:proguard for the full output.
[error] (proguard:proguard) Proguard failed with exit code [1]
[error] Total time: 16 s, completed Apr 19, 2014 2:27:56 PM
Why could be the reason for the error?

It appears that ProGuard and hence sbt-proguard don't support Java 8 yet and changing the version of Java used in the script to launch sbt helped.
[sbt-updates]> show proguard:proguard
[info] Compiling 8 Scala sources to /Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes...
[warn] there were 6 feature warning(s); re-run with -feature for details
[warn] one warning found
[info] ProGuard, version 4.9
[info] Reading program directory [/Users/jacek/oss/sbt-updates/target/scala-2.10/sbt-0.13/classes] (filtered)
[info] Reading program jar [/Users/jacek/.ivy2/cache/org.scalaz/scalaz-concurrent_2.10/bundles/scalaz-concurrent_2.10-7.1.0-M6.jar] (filtered)
...
This is with the following version of Java 7:
$ /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

The question is really interesting and i was facing the same problem with the only difference that i added Proguard programmatically by using maven. Consequently, i considered that it will be helpful to post my solution although it is a bit different from the main question. For all those that using maven and faces the same problem, my workaround fix was to update the version of Proguard by using it as runtime inside the plugin, so the working pom.xml looks like this
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.14</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<obfuscate>true</obfuscate>
<attach>true</attach>
<appendClassifier>false</appendClassifier>
<addMavenDescriptor>true</addMavenDescriptor>
<injar>${project.build.finalName}-jar-with-dependencies.jar</injar>
<injarNotExistsSkip>true</injarNotExistsSkip>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
<lib>${java.home}/lib/ext/sunjce_provider.jar</lib>
</libs>
<options>
<option>-allowaccessmodification</option>
<option>-optimizationpasses 3</option>
<option>-overloadaggressively</option>
<option>-repackageclasses ''</option>
<option>-dontusemixedcaseclassnames</option>
<option>-dontskipnonpubliclibraryclasses</option>
<option>-flattenpackagehierarch</option>
<option>-dontwarn</option> <!-- added option to ignore com.sun missing classes -->
<option>-keep public class com.StocksNews.App {
public static void main(java.lang.String[]);
}
</option>
</options>
</configuration>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>6.1.1</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>

It's possible to update the version of Proguard that sbt-proguard uses by changing the key proguardVersion in build.sbt to a setting newer than 5.0, e.g.
ProguardKeys.proguardVersion in Proguard := "5.2.1"
See: https://github.com/sbt/sbt-proguard/issues/5

I fixed that by update to latest version of ProGuad from link below
Sourceforge ProGuard page

Add classpath "com.guardsquare:proguard-gradle:7.0.1" in the project level build.gradle to resolve the error. I have solved this issue by adding the same.
I will recommend you to upgrade the Gradle Version to 7.x.x, which will remove ProGuard and you have to migrate to R8, as R8 is backward compatible with your exisiting code ProGuard rules. For Migration please read docs other you will waste alot time in figuring out some feature is not working after migration same happened to me.

Related

I am getting this sbt error , Is there any way to fix this issue

I have this issue while running sbt package command
C:\Users\U101\IdeaProjects\sbt1>sbt package
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: Ignoring option MaxPermSize; support was removed in 8.0
[info] welcome to sbt 1.4.7 (Oracle Corporation Java 10.0.2)
[info] loading global plugins from C:\Users\U101\.sbt\1.0\plugins
[info] loading project definition from C:\Users\U101\IdeaProjects\sbt1\project
[info] loading settings for project sbt1 from build.sbt ...
[info] set current project to sbt1 (in build file:/C:/Users/U1081739/IdeaProjects/sbt1/)
[info] compiling 10 Scala sources to C:\Users\U1081739\IdeaProjects\sbt1\target\scala-2.11\classes ...
[info] Non-compiled module 'compiler-bridge_2.11' for Scala 2.11.12. Compiling...
error: java.lang.NullPointerException
| => sat scala.reflect.io.JavaToolsPlatformArchive.iterator(ZipArchive.scala:301)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.reflect.io.AbstractFile.foreach(AbstractFile.scala:92)
at scala.tools.nsc.util.DirectoryClassPath.traverse(ClassPath.scala:277)
at scala.tools.nsc.util.DirectoryClassPath.x$15$lzycompute(ClassPath.scala:299)
at scala.tools.nsc.util.DirectoryClassPath.x$15(ClassPath.scala:299)
at scala.tools.nsc.util.DirectoryClassPath.packages$lzycompute(ClassPath.scala:299)
at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:299)
at scala.tools.nsc.util.DirectoryClassPath.packages(ClassPath.scala:264)
at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:358)
at scala.tools.nsc.util.MergedClassPath$$anonfun$packages$1.apply(ClassPath.scala:358)
at scala.collection.Iterator$class.foreach(Iterator.scala:891)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
at scala.tools.nsc.util.MergedClassPath.packages$lzycompute(ClassPath.scala:358)
at scala.tools.nsc.util.MergedClassPath.packages(ClassPath.scala:353)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$1.apply$mcV$sp(SymbolLoaders.scala:269)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$1.apply(SymbolLoaders.scala:260)
at scala.tools.nsc.symtab.SymbolLoaders$PackageLoader$$anonfun$doComplete$1.apply(SymbolLoaders.scala:260)
at scala.reflect.internal.SymbolTable.enteringPhase(SymbolTable.scala:235)
Can you help please
JDK installed is 1.8 in my laptop
I added jdk 8 in my environment variables, i also installed sbt sbt-0.13.18 , i dont know how it takes sbt 1.4.7

sbt-proguard issue with Java 1.8

I'm trying to get smaller scalar executable jar file with sbt-proguard.
I added project/plugin.sbt these two lines of code:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.13.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")
The first one is to get uberjar file, and I could get uberjar with sbt assembly that works fine.
Then, I executed sbt proguard:proguard to get this error message.
[error] Error: Can't read [/Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Contents/Home/jre/lib/rt.jar] (Can't process class [apple/applescript/AppleScriptEngine.class] (Unsupported class version number [52.0] (maximum 51.0, Java 1.7)))
java.lang.RuntimeException: Proguard failed with exit code [1]
at scala.sys.package$.error(package.scala:27)
...
at java.lang.Thread.run(Thread.java:745)
[error] (proguard:proguard) Proguard failed with exit code [1]
From the hint from this post: ProGuard says Unsupported class version number [52.0] (maximum 51.0, Java 1.7) with sbt-proguard,
I switched to both Java 1.7 and Java 1.6 with export JAVA_HOME=/usr/libexec/java_home -v '1.6*' command to run proguard to get the slim-lined jar file, but this doesn't run.
Invalid or corrupt jarfile target/scala-2.11/proguard/myproject_2.11-1.0.jar
What might be wrong? These are the lines that are added to build.sbt.
proguardSettings
ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")
ProguardKeys.options in Proguard += ProguardOptions.keepMain("core.HelloWorld")
I believe this is documented in the pro guard docs.
Running your application with java -classpath <jarpath> --class classname <program-arguments> should work.
This happens because pro guard by default removes all MANIFEST files from the jar hence the java runtime cannot find the jar class entries. Another way to do this would be to keep the MANIFEST.md file and run it using the java -jar option but I have never tried that.
Define a recent Proguard version that supports Java 1.8
ProguardKeys.proguardVersion in Proguard := "5.3.3"
Also a couple of useful ones if you run out of mem are
javaOptions in (Proguard, ProguardKeys.proguard) := Seq("-Xmx2G")
javaOptions in (Proguard, ProguardKeys.proguard) += "-Xss1G"

Spark: A signature in package.class refers to type compileTimeOnly

When trying to build MLlib example with Spark 1.2.1 using SBT I get the whole bunch of strange compilation errors. The same code builds fine with Spark 1.1.0. For Spark 1.2.1 I use the following SBT build file:
name := "Test"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" % "spark-mllib_2.11" % "1.2.1" % "provided"
As a result I get the following set of strange errors:
[info] Compiling 1 Scala source to /home/test/target/scala-2.10/classes...
[error] bad symbolic reference. A signature in package.class refers to type compileTimeOnly
[error] in package scala.annotation which is not available.
[error] It may be completely missing from the current classpath, or the version on
[error] the classpath might be incompatible with the version used when compiling package.class.
[error] /home/test/src/main/scala/Test.scala:16: Reference to method augmentString in object Predef should not have survived past type checking,
[error] it should have been processed and eliminated during expansion of an enclosing macro.
[error] val parsedData = data.map(s => Vectors.dense(s.split(' ').map(_.toDouble))).cache()
[error] /home/test/src/main/scala/Test.scala:16: Reference to method augmentString in object Predef should not have survived past type checking,
[error] it should have been processed and eliminated during expansion of an enclosing macro.
[error] val parsedData = data.map(s => Vectors.dense(s.split(' ').map(_.toDouble))).cache()
[error] ^
[error] three errors found
[error] (compile:compile) Compilation failed
[error] Total time: 21 s, completed 26.02.2015 17:47:29
How to fix this? It would be great if somebody could post a general SBT to build Spark 1.2.1 + MLlib code. Thanks!
Try changing the libraryDependencies line to the following:
libraryDependencies += "org.apache.spark" %% "spark-mllib" % "1.2.1" % "provided"
You are using Scala 2.10.4 and you are trying to install the Spark library for Scala 2.11.x - the %% will automatically select the correct Scala library version for you.
I am using IntelliJ to compile spark 1.6.0 code. And faced the same errors. [ERROR] error: bad symbolic reference. A signature in package.class refers to type compileTimeOnly.
I solve this problem by adding Scala language related dependencies to the project. Maybe maven can't use the Scala config from Intellij. So we should explicitly specify the Scala dependencies.
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-reflect</artifactId>
<version>2.10.6</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.6</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<version>2.10.6</version>
</dependency>

How to run jar generated by package (possibly with other jars under lib)?

How can I run .jar file which is generated by sbt's package?
I created a really simple example with a single .scala source:
package org.pack {
class ScalaParser(files: Array[String]) {
def doAll() = {
println("hello")
}
}
object Main {
def main(args: Array[String]): Unit = {
val sp = new ScalaParser(args)
sp.doAll()
}
}
}
After running
$ sbt
> compile
> package
.jar is created in /target/scala-<version>. If I try to run it, it fails giving this error:
$ java -jar package_2.9.2-0.1.jar
Exception in thread "main" java.lang.NoClassDefFoundError: scala/ScalaObject
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at org.pack.Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.ScalaObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 13 more
Note that no external libraries are used and sbt compile run works fine.
I attached the whole project including generated .jar on dropbox.
What is really weird is the fact that .jar Manifest contains right class to load, i.e. org.pack.Main. Maybe it is caused by something else.
System info
$ java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)
$ scala -version
Scala code runner version 2.9.2 -- Copyright 2002-2011, LAMP/EPFL
Additional question - what if I had some external .jars in /lib? How can I assure that they are packed? I need one .jar runnable on (possibly) every JVM.
Thanks for help.
You can use the sbt plugin sbt-assembly:
sbt-assembly >= 0.12.0 with sbt >= 0.13.6
Since sbt-assembly is now an auto plugin, it is sufficient to add project/assembly.sbt to your sbt project:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.5")
sbt-assembly 0.11
Add project/assembly.sbt to your sbt project:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
Add assembly.sbt as well:
import AssemblyKeys._ // put this at the top of the file
assemblySettings
Usage
This gives you another sbt command:
sbt assembly
which produces a "fat jar" (which includes all dependencies, including the Scala libraries).
Now you can start your program
java -cp .../package-assembly.jar
so you only need a Java installation and the "fat jar".
For those who do not wish to build a fat jar, all dependencies will have been downloaded as part of a successful run of sbt package. Classpath information is stored in a file within the target directory, which can be passed into the java command.
Example:
sbt package
java -cp target/scala-2.11/yourproject.jar:$(cat target/streams/compile/dependencyClasspath/\$global/streams/export) Main
Try
scala package_2.9.2-0.1.jar
Update
From Java the command would look like this,
java -cp $SCALA_HOME/lib/scala-library.jar -jar package_2.9.2-0.1.jar
Yet in the classpath you may need to add additional jar's, for instance -cp "jar1.jar:jar2.jar"

issue when building NPanday Building a web application

[UPDATE]
the clean goal runs smoothely all over the projects of the solution, the problem now while running the compile goal, below the error message:
[INFO] Total time: 19.427s
[INFO] Finished at: Fri Jun 29 11:46:28 WEST 2012
[INFO] Final Memory: 15M/306M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.npanday.plugins:maven-aspx-plugin:1.4.0-incubating:compile (default-compile) on project B3GMcsInterface: NPANDAY-900-006: Unable to Compile: Language = ASP, Vendor = null, ArtifactType = asp, Source Directory = C:\Users\CASA-WS001\Desktop\Gateway\ProjectName: NPANDAY-040-001: Could not execute: Command = cmd.exe /X /C "aspnet_compiler -v " /MyArtifactId" -p C:\Users\CASA-W~1\AppData\Local\Temp\maven-aspx-plugin-3088047295012139775\src -u -f C:\Users\CASA-W~1\AppData\Local\Temp\maven-aspx-plugin-3088047295012139775\dest -nologo -fixednames", Result = 1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :B3GMcsInterface
NPanday Execution Failed!, with exit code: 1
[END OF UPDATE]
i'm trying to make the build of simple web application using NPanday, i am using the incubating 1.4.0 plugin for VS2010, i have successfully built C# Console or Libraries Projects using maven, but when i tried to clean a web application i encounter this kind of error
Below is the error output.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.628s
[INFO] Finished at: Tue Jun 26 17:53:56 WET 2012
[INFO] Final Memory: 6M/16M
[INFO] ------------------------------------------------------------------------
[ERROR] Error resolving version for plugin 'npanday.plugin:maven-aspx-plugin' from the repositories [local (C:\Users\user1.m2\repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository -> [Help1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/PluginVersionResolutionException
any help is appreciated.
Thank You.
The problem is the "npanday.plugin" in "npanday.plugin:maven-aspx-plugin"... It must be wrongly stated in one of the life cycles.
Things have moved to "org.apache.npanday.plugins": http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22maven-aspx-plugin%22
Try using 1.5.0-SNAPSHOT from the following repository. It contains a mass of improvements! I'm using it in production.
<pluginRepositories>
<pluginRepository>
<releases>
<enabled>false</enabled>
</releases>
<id>npanday.snapshots</id>
<name>NPanday Snapshot Repository</name>
<url>http://vmbuild.apache.org/archiva/repository/npanday-snapshots</url>
</pluginRepository>
</pluginRepositories>
I think you have to use a repository manager and define a supplemental repository which contains the given dependencies / plugins.
Error is related plugins order in pom.xml:
If maven-compile-plugin is before maven-aspx-plugin, you get the error.
But if the order is maven-aspx-plugin and then maven-compile-plugin, mvn compile works
Snip of the correct pom.xml:
....
<plugins>
<plugin>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>maven-aspx-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<frameworkVersion>4.0</frameworkVersion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.npanday.plugins</groupId>
<artifactId>maven-compile-plugin</artifactId>
<version>1.4.0-incubating</version>
<extensions>true</extensions>
....

Resources