When I configure the scmchangelog-plugin, as written in the examples/tutorial, and run the site-generation, the username and password I have set are ignored.
The documentation says that username and password which should be used to access the SCM can be configured in the plugin-configuration. This looks like this:
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>scmchangelog-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<grammar>REMY</grammar>
<connectionUrl>scm:svn:svn+ssh://repo.lan/repo/project/trunk</connectionUrl>
<username>user</username>
<password>password</password>
</configuration>
</plugin>
</plugins>
</reporting>
When i run the site-generation (mvn site), the output on the commandline says
[INFO] Executing: /bin/sh -c cd /tmp && svn --username user --password '*****'
--non-interactive list --xml svn+ssh://repo.lan/repo/project/tags/
But I'm still prompted for the the password and the user used to access the SCM is the one running the mvn command.
Any ideas what could be wrong?
Update:
I tracked down the problem to the svn command line client now.
the problem is, that when i run a command like the following
svn list --username foo --password bar --non-interactive svn+ssh://host/repo/project
the command line tool seems to ignore the given options. i'm still questioned for a password, and the user used to access the URL is the one who executes the command, and not the one set in the options.
i'm using svn version 1.4.6 here.
any ideas what might go wrong here ?
This is a known bug. The correct behavior would be to show an error that states that the --username and --password options are not supported when using an external authentication mechanism like SSH, instead of silently ignoring those options.
To fix your issue, pass your 'foo' username as part of the URL:
svn+ssh://foo#host/repo/project
and use something like ssh-agent to cache your credentials, thus avoiding the password prompt.
Do you mean the scm:changelog goal of the Maven SCM plugin? If this is the case you have two choices to ensure the SCM is passed your credentials.
Preferred approach
Some SCM providers allow you to specify a settings file below M2_HOME/conf/.scm, for example Subversion's is svn-settings.xml and CVS's is cvs-settings.xml
Your SCM provider should define how to define the configuration settings. For Subversion I end up with a file like this:
<svn-settings>
<user>[username]</user>
<password>[password]</password>
</svn-settings>
If needed, you can specify the SCM settings file in another location by passing a command-line parameter to the file:
-Dmaven.scm.svn.config_directory=your_configuration_directory
Other approach
The other (undesirable) option is to configure the scm section of the POM so that the urls contain the username and password. The implementation of this is provider-specific, but is generally of a similar form to this example for Subversion:
scm:svn:http://[user]:[password]#host/path
So your scm section in the POM would look something like this:
<scm>
<connection>scm:svn:http://[user]:[password]#host/path</connection>
<developerConnection>
scm:svn:http://[user]:[password]#host/path
</developerConnection>
<url>http://somerepository.com/viewsvn</url>
</scm>
This is obviously undesirable as your SCM credentials end up in your installed POM, you should really only use this for testing the connection in my opinion. For more information see the SCM URL Format page and details for specific SCM providers
Check if there's an alias clobbering your use of the "svn" command.
Also check if the destination host allows password-mode authentification. Might also be worth to check that the desktop doesn't fool around with some handy "keyring agent", those can interfere with svn+ssh.
Related
I'm trying to run sonarqube to scan a java project against localhost. However, when I run mvn sonar:sonar I get this error Unrecoverable indexation failures: 1 errors among 1 requests. Check Elasticsearch logs for further details. It asks me to look for an ElasticSearch file, which doesn't seem to be on my machine as when I look at the Sonarqube home directory this is what I see.
This is my pom configuration:
<jacoco-maven-plugin.version>0.8.7</jacoco-maven-plugin.version>
<sonar.version>3.9.0.2155</sonar.version>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Edit this URL for sonarQube server -->
<sonar.host.url>http://localhost:9000/</sonar.host.url>
<sonar.login>myToken</sonar.login>
<!-- Sonar-JaCoCo properties -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPaths>${basedir}/target/jacoco.exec</sonar.jacoco.reportPaths>
<sonar.web.accessLogs>true</sonar.web.accessLogs>
<java.version>17</java.version>
<sonar.exclusions>**/entity/**</sonar.exclusions>
<sonar.test.exclusions>src/test/**/*</sonar.test.exclusions>
</properties>
</profile>
And here what I see when I type sonar -v
/opt/homebrew/Cellar/sonarqube/9.8.0.63668/libexec/bin/macosx-universal-64/sonar.sh
Thank you.
Update
Adding the outpute for /var/log
"It asks me to look for an ElasticSearch file, which doesn't seem to be on my machine."
Actually, it asks you to look at the log files(!)
The default name for SonarQube's elastic search log file is es.log. If you can't find it in "obvious" places (e.g. in the "/var/log" tree on a Linux system), you should be able to find the log file using the find command; e.g.
$ sudo find / -name es.log\* | less
If that doesn't find the log file, you will need to look at your SonarQube installation's logging configuration to figure out where log4j is writing the file.
Once you have found the log file, read what it says. Note that there is information in the SonarQube Troubleshooting on common elastic search problems.
I am attempting to use the google vision library in java. The steps specify that I need to setup my auth credentials in order to start using the this library . I was able to generate my json property file from API Console Credentials page and I placed it in my spring boot app in the resources folder.
I think updated my application.properties file to include the value like so:
GOOGLE_APPLICATION_CREDENTIALS=datg-avatar-generator-9dc9155cd5bd.json
I'm also setting my property source in my controller like so:
#PropertySource("${GOOGLE_APPLICATION_CREDENTIALS}")
However, after doing that I'm still getting an error saying:
java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
I was able to configure this property using Spring Cloud GCP spring-cloud-gcp-starter-data-datastore, creating a service account project owner, copy the JSON private key to the main resources directory, and setting the following properties in the application.properties
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=classpath:<credentials-private-key>.json
from the documentation
You can find the project id by visiting this page https://support.google.com/googleapi/answer/7014113?hl=en
Go to the API Console.
From the projects list, select Manage all projects. The names and IDs for all the projects you're a member of are displayed.
You can also select the project go the settings and see the project ID
You can use application properties, but you need to use a different StorageOptions builder.
You are probably using
private static Storage storage = StorageOptions.getDefaultInstance().getService();
But if you want to skip the environment variable you need to use:
Credentials credentials = GoogleCredentials
.fromStream(new FileInputStream("path/to/file"));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials)
.setProjectId("my-project-id").build().getService();
Note that the default builder (using environment variables) is better if you are going to deploy your applications to cloud, because then this is automatically filled for you.
You need to set the shell variable. Run this command before mvn run.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/ronnyshibley/Dev/eddress-service-key.json"
For authentication using the service account key, you can set the Environment Variable in your shell.
export GOOGLE_APPLICATION_CREDENTIALS="/Users/username/directory/service-key-file-name.json"
Then you need to start your IDE from the same session. I was stuck after exporting and setting up the environment variable and was still unable to use it.
I tried quitting the current IDE window and restarted the IDE again from the same session.
In my case it was Intellij, so in the terminal itself,
cd project directory
idea .
Or you can also add the environment variable in your bash profile and then source it.
I have tried several ways to do this, and none of them worked. Maven plugin
environmentVariables is the last thing that worked without any problem.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
<executable>true</executable>
<environmentVariables>
<GOOGLE_APPLICATION_CREDENTIALS>/path/to/the/service-account.json</GOOGLE_APPLICATION_CREDENTIALS>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
You need to add env variable
GOOGLE_APPLICATION_CREDENTIALS=<path to google project json file >
If you are using IntelliJ idea, Edit the Project configuration and add the Environment variable
For images check this
https://www.twilio.com/blog/set-up-env-variables-intellij-idea-java
I'm using the maven-release-plugin. I'm trying to release a branch and it's failing when it tries to execute this command:
cmd.exe /X /C "svn --non-interactive copy --file C:\Users\USER~1\AppData\Local\Temp\maven-scm-711744598.commit --parents --revision 0 https://domain/svn/app/branches/2.4.8.x https://domain/svn/app/tags/App-2.4.8.1"
It gives this error:
svn: E195012: Unable to find repository location for 'https://domain/svn/app/branches/2.4.8.x' in revision 0
I think this is happening in the prepare goal because when it fails it says:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-release-plugin:2.5:prepare
I asked a svn expert about this, and he said:
wait, why is it trying to copy something from r0? By definition there is nothing in r0. r0 is always an empty repository, the first objects are added in r1. That's why it fails. the question is why maven tried it. If you supply a revision argument to 'svn copy' then the branch / tag you create is based on the source from the revision you specify so the source has to exist in that revision (if you don't specify, you get HEAD, i.e., the newest revision) ...and as for that, I know nothing about maven or its plugins
So why is maven trying to copy from revision 0? This is the maven command I ran:
mvn --batch-mode release:prepare release:perform
And my root pom has the maven-release-plugin defined like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5</version>
<configuration>
<autoVersionSubmodules>true</autoVersionSubmodules>
<developmentVersion>2.4.8.2-SNAPSHOT</developmentVersion>
<releaseVersion>2.4.8.1</releaseVersion>
<branchBase>https://domain/svn/app/branches</branchBase>
<tagBase>https://domain/svn/app/tags</tagBase>
</configuration>
</plugin>
Also, my scm tag looks like this:
<scm>
<connection>scm:svn:https://domain/svn/app/branches/2.4.8.x</connection>
</scm>
My svn version is 1.8.5 (r1542147)
Just wanted to add this late answer for if anyone has the same problem and the solution in the comment doesn't work.
We had the same problem in a multi module application, only our parent POM had the SCM tag (which worked perfectly in our other applications). We got the same error but could solve it by adding the corresponding SCM tag to each child POM. We never found out why this was...
As I said as a comment above:
I cleaned up EVERYTHING and ran just release:prepare by itself and it succeeded without issue. Perhaps this is a bug where running release:prepare and release:perform together will cause this
I have not run into this issue since running these commands separately.
I also had this problem. In the affected project I had a custom search and replace of some files during the validate phase and I wanted to check in the changes to Svn before tagging so I added a custom check-in action like this:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<preparationGoals>clean verify scm:checkin -Dmessage="perform release"</preparationGoals>
</configuration>
</plugin>
This had the consequences that when the release plugin tried to check in the changes in the pom file, there were no changes since they were already committed by the custom action. Thus causing this error.
I added a "includes" file list to my custom scm:checkin which only included the files that I had been tampering with and this fixed the problem for me.
The resulting configuration looked like this:
<plugin>
<artifactId>maven-release-plugin</artifactId>
<configuration>
<preparationGoals>clean verify scm:checkin -Dmessage="perform release" -Dincludes="TwogWebUtilsGrailsPlugin.groovy,plugin.xml" -DconnectionType="connection"</preparationGoals>
</configuration>
</plugin>
The reason for my custom replace action is because the project is a Grails plugin and I was following the guidelines in this blog post.
LATE EDIT: After upgrading to maven 3.2, this solution seems to break. I am back to where I started.
Is it possible to do this?
For example could one do something like:
System.getEnv("$(env.BUILD_URL)");
I do not have access to Jenkins, so can't try it out myself :(
Any help would be greatly appreciated.
Assuming you're using Maven (you've tagged this question as such), I simply add the following to my pom.xml file:
...
<properties>
<!-- Hudson properties: see http://wiki.hudson-ci.org/display/HUDSON/Building+a+software+project#Buildingasoftwareproject-HudsonSetEnvironmentVariables -->
<jenkins.buildId>${env.BUILD_ID}</jenkins.buildId>
<jenkins.buildNumber>${env.BUILD_NUMBER}</jenkins.buildNumber>
<jenkins.buildTag>${env.BUILD_TAG}</jenkins.buildTag>
<jenkins.cvsBranch>${env.CVS_BRANCH}</jenkins.cvsBranch>
<jenkins.executorNumber>${env.EXECUTOR_NUMBER}</jenkins.executorNumber>
<jenkins.hudsonUrl>${env.HUDSON_URL}</jenkins.hudsonUrl>
<jenkins.javaHome>${env.JAVA_HOME}</jenkins.javaHome>
<jenkins.jobName>${env.JOB_NAME}</jenkins.jobName>
<jenkins.svnRevision>${env.SVN_REVISION}</jenkins.svnRevision>
<jenkins.workspace>${env.WORKSPACE}</jenkins.workspace>
</properties>
...
...and then from your code you can simply do a:
String url = System.getProperty("jenkins.hudsonUrl"); // could be null
Putting these into properties makes life more simple for my purposes, especially when using Maven profiles to control my builds. For example, I make sure to create a "jenkins" profile that is activated when I build on a Jenkins build server. When this is done, all the aforementioned jenkins properties are set. When not run as a jenkins profile, those properties are set to some other default value. Anyway, that's another topic, but food for thought. Hopefully it make sense.
I'm writing a Maven plugin which I'd like to prompt for a simple user input and decide whether to halt the plugin's execution.
I'd like to do something like this:
$> mvn myplugin:run
[MAVEN] would you like to continue? [default value: y] _
I've tried using maven-antrun-plugin as described here, but in this case Maven gets user input when I build my plugin. Instead, I'd like to retrieve input when user is running my plugin from within some other app that has declared my plugin (confusing?)
Use a Prompter component and have it injected in your plugin (assuming you are using Maven plugin annotations, if not use the equivalent javadoc tags):
#Component
private Prompter prompter;
And to use it:
String name = prompter.prompt("Please enter your name");
Pull in this dependency in your plugin's POM:
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-interactivity-api</artifactId>
<version>1.0-alpha-6</version>
</dependency>
The prompter component is used by the release plugin for prompting the user for tags and versions and the archetype plugin as well.
Don't do this. If you need to supply data to a mojo, do it via configuration.
The behavior of your Maven build should be entirely predictable based on your POM and the goals & options supplied to the Maven command line. If you allow a user to feed in additional information during the build, your POM no longer completely describes your project.
Also, it would prevent any automated build server doing its job.
as variant, to not break maven way as wool.in.silver wrote, you can use shell script that will prompt values and then call maven with gathered values as parameters