sonarRunner java.lang.OutOfMemoryError: PermGen sp

2019-07-24 11:24发布

Environment:
1. Linux
2. Gradle 1.6/7
3. Language - Java

gradle clean build jacocoTestReport - working fine.

Recently followed the documentation provided by SonarQube installation at: http://docs.sonarqube.org/display/SONAR/Running+SonarQube+as+a+Service+on+Linux (sonar start, sonar status, sonar stop etc)...commands will work at this point.

Changed gradle build script acc. to Gradle SonarRunner help page at: http://www.gradle.org/docs/current/userguide/sonar_runner_plugin.html

While running sonarRunner task - I get the following error:

:sonarRunner
18:56:03.997 INFO  - Load batch settings
18:56:04.140 INFO  - User cache: /production/c123456/jenkins/.sonar/cache
18:56:04.146 INFO  - Install plugins
18:56:04.851 INFO  - Install JDBC driver
18:56:04.858 WARN  - H2 database should be used for evaluation purpose only
18:56:04.858 INFO  - Create JDBC datasource for jdbc:h2:tcp://devserver11.tr.company.com:9092/sonar
18:56:05.870 INFO  - Initializing Hibernate
:sonarRunner FAILED
java.lang.OutOfMemoryError: PermGen space
> Building-bash-3.2$

Installed sonar at /production/c123456/sonar i.e. - sonar/conf/sonar.properties - everything looks correct - sonar/conf/wrapper.properties - contains valid values for JAVA opts i.e.

# Java Additional Parameters
wrapper.java.additional.1=-Djava.awt.headless=true
wrapper.java.additional.2=-XX:MaxPermSize=1024m
wrapper.java.additional.3=-XX:+HeapDumpOnOutOfMemoryError
wrapper.java.additional.4=-XX:+CMSClassUnloadingEnabled
wrapper.java.additional.5=-XX:+UseConcMarkSweepGC

# RECOMMENDED : uncomment if Java Virtual Machine is a JDK but not a JRE. To know which JVM you use, execute
# 'java -version'. JDK displays 'Server VM'.
wrapper.java.additional.4=-server

# Initial Java Heap Size (in MB)
wrapper.java.initmemory=512

# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=1024
  1. Can someone help what I could be missing to get this error message - PermGen space issue NOTE: This was happening from one Linux machine, so I tried installing Sonar on other Linux machine, still got the same error message.

  2. I installed SonarQube/Runner on my own local Windows machine and pointed build.gradle sonarRunner section to use host url as my local machine / host url my machine name (fqdn) with port (:9000) etc and same for jdbc h2 tcp way.

    While running "gradle clean build jacocoTestReport sonarRunner", it passes the above error but gives me another strange one. C:\work is my workspace where I have checked out the project: Project_A_Svc (service project - Java source).

    :sonarRunner FAILED

    FAILURE: Build failed with an exception.

    • What went wrong: Execution failed for task ':sonarRunner'.

      org.sonar.runner.RunnerException: The folder 'C:\work\Project_A_Svc\src\main\java' does not exist for 'project_a_svc:project_a_svc' project (base directory = C:\work\Project_A_Svc)

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

    BUILD FAILED

    Total time: 38.124 secs

Why Gradle is trying to look for "src/main/java" when my source code doesn't even have that folder structure. Gradle default structure is to use "src/main/java" for java source code location but my build.gradle does have sourceSets section where I have mentioned the location to find java source. I have tried multiple ways to set source Dirs for src java / tests but it's still trying to look for "src/main/java".

build.gradle snapshost

apply plugin: 'java'
apply plugin: 'sonar-runner'

   main {
      java {
         srcDir 'src/java'
      }
   }
   test {
      java {
         srcDir 'test/java'
      }
   }
   integrationTest {
      java {
         srcDir 'src/java-test'
      }
   }
}

and

sonarRunner section within build.gradle is:

def sonarServerUrl = "devserver11.tr.company.com"
sonarRunner {
   sonarProperties {
      property "sonar.host.url", "http://$sonarServerUrl:9000"
  // these are default settings for the in-memory database.  Change if using a persistent DB.
  property "sonar.jdbc.url", "jdbc:h2:tcp://$sonarServerUrl:9092/sonar"
  property "sonar.jdbc.driverClassName", "org.h2.Driver"
  property "sonar.jdbc.username", "sonar"
  property "sonar.jdbc.password", "sonar"

  //properties ["sonar.sources"] += sourceSets.main.java.srcDirs
  //properties ["sonar.tests"] += sourceSets.test.java.srcDirs
  //----
  properties["sonar.sources"] = "src/java"
  properties["sonar.tests"] = "test/java"

   }
}

Any help? Thanks a lot.

2条回答
再贱就再见
2楼-- · 2019-07-24 11:53

I got some progress.

Steps

  1. DIDN'T change anything in sonar/conf/sonar.properties, wrapper.properties, sonar-runner/conf/sonar-runner.properties. MADE sure the host url value is same in sonar.properties and sonar-runner.properties.

  2. Go to the workspace (where you have source code installed).

  3. Ran sonar-runner (an executable) - it will show the path/file It gave the error that I need sonar-project.properties as I was missing some variables required by Sonar.

    Used the link

  4. Found SCM Provider not set. Used the link: http://jira.codehaus.org/browse/ACT-1714 to resolve it.

  5. ran sonar-runner again, it went fine. (NOTE: This command is different than running sonarRunner as that's Gradle's sonar runner task).

  6. Went to SonarQube dashboard and there's stuff showing now.

PENDING for tomorrow:

  1. To the following at Linux command line and from Jenkins (job calling gradle tasks). gradle clean build jacocoTestReport sonarRunner

Update:

  • Tried running:

gradle clean build jacocoTestReport - works

gradle clean build jacocoTestReport sonarRunner -- Fails saying src/main/java doesn't exist

gradle clean build jacocoTestReport sonarRunner -Dsonar.sources=src/java -- WORKED

gradle clean build jacocoTestReport sonarRunner -Dsonar.sources="src/java,test/java,src/java-test" -- DID NOT WORKED (PermGen java error)

gradle clean build jacocoTestReport sonarRunner -Dsonar.sources="src/java" -- DID NOT WORKED (PermGen java error)

gradle clean build jacocoTestReport sonarRunner -Dsonar.sources=src/java -- DID NOT WORKED (PermGen java error)

gradle sonarRunner -Dsonar.sources=src/java,test/java,src/java-test -- DID NOT WORKED (Error is charset can't read or import - charset UTF-8 or whatever I end up setting for sonar.sourceEncoding)

gradle clea build jacocoTestReport -- WORKED

then

gradle sonarRunner -Dsonar.sources="src/java" -- WORKED

I have tried setting MaxPernGen in sonar/conf/wrapper.properties to various values like 128, 512, 1024, 2048, ... upto 8000m ... didn't work in resolving the following error - while running all gradle tasks in one command.

:sonarRunner FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':sonarRunner'.
> java.lang.OutOfMemoryError: PermGen space

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Wondering why I'm getting this error as soon as I run:

:gradle clean build jacocoTestReport sonarRunner"




OK - got PermGen Memory issue resolved.

Steps: 1. In my ~/.bashrc or ~/.bash_profile. I created the following variable

GRADLE_OPTS=” -XX:MaxPermSize=512m"
  1. Run "which gradle" or basically find which gradle file (shell or .bat) is used. Go to that path and open "gradle" / "gradle.bat" (for windows) file.

  2. Make the following changes.

    DEFAULT_JVM_OPTS="$JAVA_OPTS $GRADLE_OPTS"
    
  3. Do ". ~/.bash_profile" or ". ~/.bashrc" .... --OR open a new putty session.

  4. Make sure PATH variable has gradle HOME / bin in it (Linux/Windows)

  5. Ran the following command (this time didn't show PermGen error which I got earlier) from workspace:

    gradle clean build jacocoTestReport sonarRunner

    :) Time to go home early today.

  6. Other similar variables are: GRADLE_OPTS / JAVA_OPTS / SONAR_RUNNER_OPTS (where -XX:Max.. value can be set) at server(putty session level) or in IDEs or in Jenkins.

Thanks Allyn for the hint.

查看更多
Root(大扎)
3楼-- · 2019-07-24 11:55

If you use the Gradle Wrapper, you can specify GRADLE_OPTS there, which should work on Jenkins as well.

查看更多
登录 后发表回答