Aether, get artifact from local repo - maven

there are many questions related to
<dependency>
<groupId>com.jcabi</groupId>
<artifactId>jcabi-aether</artifactId>
<version>0.9</version>
</dependency>
It works perfectly when I need to get an artifact from remote repo.
Unfotunately, I can't find a way to force aether to get artifact from local repo.
It prints to console:
2014-07-21 18:11:40 ERROR MethodValidator.error: - JSR-303 validator failed to initialize: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath. (see http://www.jcabi.com/jcabi-aspects/jsr-303.html)
2014-07-21 18:11:40 INFO NamedThreads.info: - jcabi-aspects 0.7.22/fd7496f started new daemon thread jcabi-loggable for watching of #Loggable annotated methods
2014-07-21 18:11:41 WARN LogTransferListener.warn: - #transferFailed('GET FAILED https://my.remote.repo/nexus/cont..243..tory-uploader-1.0.0-${revision.suffix}.pom'): in 29µs
2014-07-21 18:11:41 WARN LogTransferListener.warn: - #transferFailed('GET FAILED http://repo.maven.apache.org/maven2/ru..220..tory-uploader-1.0.0-${revision.suffix}.pom'): in 21µs
2014-07-21 18:11:41 ERROR Aether.error: - #resolve(my.group.id:my-artifact-i-want-to-get:groovy:installer:1.0.0-SNAPSHOT, 'runtime', org.sonatype.aether.util.filter.ScopeDependencyFilter#9076fc75): thrown org.sonatype.aether.resolution.DependencyResolutionException(failed to load 'my.group.id:my-artifact-i-want-to-get:groovy:installer:1.0.0-SNAPSHOT (runtime)' from ["shared-nexus (https://my.remote.repo/nexus/content/groups/all-repos/, releases+snapshots) with kyc.developer", "central (http://repo.maven.apache.org/maven2, releases) without authentication"] into /home/ssa/.m2/repository) out of com.jcabi.aether.Aether#fetch[198] in 166ms
2014-07-21 18:11:41 ERROR Aether.error: - #resolve(my.group.id:my-artifact-i-want-to-get:groovy:installer:1.0.0-SNAPSHOT, 'runtime'): thrown org.sonatype.aether.resolution.DependencyResolutionException(failed to load 'my.group.id:my-artifact-i-want-to-get:groovy:installer:1.0.0-SNAPSHOT (runtime)' from ["shared-nexus (https://my.remote.repo/nexus/content/groups/all-repos/, releases+snapshots) with kyc.developer", "central (http://repo.maven.apache.org/maven2, releases) without authentication"] into /home/ssa/.m2/repository) out of com.jcabi.aether.Aether#fetch[
artifact is in local repo, but aether fails to find it...
what do I do wrong?
My code:
List remoteRepos, File localRepoRoot are "injected" from maven plugin. This class is used from maven-plugin.
MavenHelperAether(List<RemoteRepository> remoteRepos, File localRepoRoot) {
this.remoteRepos = remoteRepos
this.localRepoRoot = localRepoRoot
}
/**
* Resolves artifact using artifact coordinates
* #param artifactCoords is an artifact you need
* #param remoteLookup is ignored. It's a part of backward compatibility.
*
* #return {#link File} pointing to artifact
* */
public File resolveArtifact(String artifactCoords, boolean remoteLookup = false){
LOG.debug("resolving artifact $artifactCoords ... using localRepo[$localRepoRoot.absolutePath] and remoteRepos [$remoteRepos]")
def aether = new Aether(remoteRepos, localRepoRoot)
def artifact = new DefaultArtifact(artifactCoords)
Collection<Artifact> deps = []
try{
deps = resolveInRemoteRepositories(aether, artifact)
LOG.debug("Resolved artifact path ${deps.iterator().next().file.absolutePath }")
return deps.iterator().next().file
}
catch (DependencyResolutionException | IllegalArgumentException e){
LOG.warn("Can't fetch $artifact from remote repos. Falling back to local repository...", e)
def localArtifact = resolveInLocalRepo(artifact)
if(localArtifact.exists()){
return localArtifact;
}else{
throw new InstallerException("Can't locate artifact [$artifact] in local repo using path [$localArtifact.absolutePath]")
}
}
}
private Collection<Artifact> resolveInRemoteRepositories(Aether aether, DefaultArtifact artifact){
LOG.debug("Trying to resolve $artifact in remote repositories...")
aether.resolve(artifact,JavaScopes.RUNTIME)
}
private File resolveInLocalRepo(DefaultArtifact artifact){
LOG.debug("Trying to resolve $artifact in local repository...")
def localRepoManager = new SimpleLocalRepositoryManager(localRepoRoot)
new File(localRepoManager.getPathForArtifact(artifact, true))
}

You can just create local-remote repo and give it to request:
RemoteRepository local = new RemoteRepository.Builder("local", "default", "file:c:/Users/blah/.m2/repository").build();
RemoteRepository central = new RemoteRepository.Builder("central", "default", "http://central.maven.org/maven2/").build();
collectRequest.setRepositories( Arrays.asList(local, central));

Take look at this code:
https://github.com/liferay/liferay-blade-cli/blob/28556e7e8560dd27d4a5153cb93196ca059ac081/com.liferay.blade.cli/src/com/liferay/blade/cli/aether/AetherClient.java
Aether uses local repository by default, so simply set to not use remote if this is not required:
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession()
session.setUpdatePolicy(RepositoryPolicy.UPDATE_POLICY_NEVER)

I can't say is it good or bad, but I've used this code, it works:
private File resolveInLocalRepo(DefaultArtifact artifact){
LOG.debug("Trying to resolve $artifact in local repository...")
def localRepoManager = new SimpleLocalRepositoryManager(localRepoRoot)
def pathToLocalArtifact = localRepoManager.getPathForLocalArtifact(artifact)
LOG.debug("pathToLocalArtifact: [$pathToLocalArtifact]")
new File("$localRepoRoot.absolutePath/$pathToLocalArtifact")
}
localRepoRoot is a file pointing to the root of local repo.

Related

Could not resolve all dependencies for configuration [custom configuration]

Please, I'm working on converting a gradle 2.1 project to 6.0, but I get this error.
Could not resolve all dependencies for configuration ':driver'.
> Cannot convert the provided notation to a File or URI: classesDirs.
The following types/formats are supported:
- A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
- A String or CharSequence URI, for example 'file:/usr/include'.
- A File instance.
- A Path instance.
- A Directory instance.
- A RegularFile instance.
- A URI or URL instance.
When running
configurations.driver.each {File file ->
loader.addURL(file.toURL())
}
driver is a custom configuration define as
configurations {
driver
}
dependencies {
driver 'org.drizzle.jdbc:drizzle-jdbc:1.3'
}
Please any ideas how to fix?
Fixed by using
sourceSets.main.output.resourcesDir = sourceSets.main.java.outputDir
sourceSets.test.output.resourcesDir = sourceSets.test.java.outputDir
Instead of
sourceSets.main.output.resourcesDir = sourceSets.main.output.classesDirs
sourceSets.test.output.resourcesDir= sourceSets.test.output.classesDirs

Adding a custom java library using gradle from gitlab with a provisioned deploy token

I got this working with my public github account where I was using something like this:
maven {
url "https://raw.githubusercontent.com/tvelev92/reactnativeandroidmaven/master/"
}
Then I decided I want it to be private and I put it on my company's gitlab and provisioned an access token however, I cannot figure out how to change build.gradle to accomplish a successful import of the pom file. Here is what I have however, I am receiving a 401 server response.
maven {
url "https://gitlabdev../../mobile/mysdk"
credentials(HttpHeaderCredentials) {
name = "password"
value = "..."
}
authentication {
header(HttpHeaderAuthentication)
}
}
please try:
url "https://raw.githubusercontent.com/tvelev92/reactnativeandroidmaven/raw/master/"

JHipster Sample Gradle App liquibaseDiffChangelog command is throwing a "Driver class was not specified" exception

I am trying to get the Gradle liquibaseDiffChangelog command working with the JHipster Sample Gradle App and I am getting the following exception:
liquibase.exception.DatabaseException: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:157)
at liquibase.integration.commandline.Main.doMigration(Main.java:915)
at liquibase.integration.commandline.Main.run(Main.java:180)
at liquibase.integration.commandline.Main.main(Main.java:99)
Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:247)
at liquibase.database.DatabaseFactory.openDatabase(DatabaseFactory.java:151)
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:85)
... 3 common frames omitted
Caused by: java.lang.RuntimeException: Cannot find database driver: Driver class was not specified and could not be determined from the url ()
at liquibase.database.DatabaseFactory.openConnection(DatabaseFactory.java:199)
... 5 common frames omitted
:liquibaseDiffChangelog FAILED
I have modified the liquibase.gradle file to the following to work with my local MySQL database:
configurations {
liquibase
}
dependencies {
liquibase group: 'org.liquibase.ext', name: 'liquibase-hibernate4', version: liquibase_hibernate4_version
}
task liquibaseDiffChangelog(dependsOn: compileJava, type: JavaExec) {
group = "liquibase"
classpath sourceSets.main.runtimeClasspath
classpath configurations.liquibase
main = "liquibase.integration.commandline.Main"
args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
args "--referenceUrl=hibernate:spring:com.mycompany.myapp.domain?dialect=org.hibernate.dialect.MySQL5Dialect"
args "--username=root"
args "--password=password"
args "--url=jdbc:mysql://localhost:3306/app"
args "--driver=com.mysql.jdbc.Driver"
args "diffChangeLog"
}
def buildTimestamp() {
def date = new Date()
def formattedDate = date.format('yyyyMMddHHmmss')
return formattedDate
}
The parameters all appear to be correct and similar to the ones described in this guide that uses Maven.
Is there some other step in this process that I am missing and that I cannot find documented anywhere?
Do I need to download the MySQL connector separately and place it in a certain location?
The JHipster Liquibase documentation does not mention any other steps.
the problem is that you need also to config the url against your liquibase should run the diff. The config file that you need to edit is liquibase.gradle in the folder gradle in the root of your app:
args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
args "--referenceUrl=hibernate:spring:io.github.jhipster.sample.domain?dialect=&hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy"
args "--username=jhipsterGradleSampleApplication"
args "--password="
args "--url=jdbc:mysql://localhost:3306/yourDB"
args "--driver=com.mysql.jdbc.Driver"
args "diffChangeLog"
You need to change the url, username and password in order to work with your db. Cheers!
Use o
?dialect=org.hibernate.dialect.MySQL5InnoDBDialect"

SonarQube Eclipse plugin : change default server configuration

I try to change the default SonarQube server value in SonarQube Eclipse plugin (v3.2)...
Using the pluginCustomization process (argument -pluginCustomization myPrefs.ini in eclipse.ini file), I add the same value as result of eclipse preferences export :
# SonarQube default configuration server
org.sonar.ide.eclipse.core/servers/http\:\\2f\\2fsonar.mycompany.org/auth=true
But after workspace creation, the default value is always http://localhost:9000
This is a bug ? or there is a best common way to do that ?
Thanks for the tips.
24/09/2015 Update : Fixed with SonarQube Eclipse plugin v3.5 (see SONARCLIPS-428).
It is not the answer but a trick ... if you consider :
Having your own plugin with some IStartup process in the Eclipse distribution
You are using a proxy with the same credentials as SonarQube
This code could help you in an earlyStartup() method :
// Plugin dependencies : org.sonar.ide.eclipse.core, org.eclipse.core.net
// Write a process to do this code once (IEclipsePreferences use)
// ...
String userName = null;
String password = null;
// Get first login/password defined in eclipse proxy configuration
BundleContext bc = Activator.getDefault().getBundle().getBundleContext();
ServiceReference<?> serviceReference = bc.getServiceReference(IProxyService.class.getName());
IProxyService proxyService = (IProxyService) bc.getService(serviceReference);
if (proxyService.getProxyData() != null) {
for (IProxyData pd : proxyService.getProxyData()) {
if (StringUtils.isNotBlank(pd.getUserId()) && StringUtils.isNotBlank(pd.getPassword())) {
userName = pd.getUserId();
password = pd.getPassword();
break;
}
}
}
// Configure SonarQube with url and proxy user/password if exist
SonarCorePlugin.getServersManager().addServer("http://sonarqube.mycompany.com", userName, password);
// Store process done in preferences
// ...

OSGi bundle installation using pax-exam issue

I'm trying to write spock pax exam extension, but figured out a problem with bundle installation using server mode.
Here is my code
void visitSpecAnnotation(RunPax annotation, SpecInfo sp) {
sp.addListener(new AbstractRunListener() {
private TestContainer container
#Override
void beforeSpec(SpecInfo spec) {
ExamSystem system = PaxExamRuntime.createServerSystem(
CoreOptions.options(
karafDistributionConfiguration("mvn:org.apache.servicemix/apache-servicemix/4.4.1-fuse-03-06/tar.gz", // artifact to unpack and use
"servicemix", // name; display only
"2.2.4")
.unpackDirectory(new File("target/paxexam/unpack/"))
.useDeployFolder(false),
//debugConfiguration("5005", true),
keepRuntimeFolder(),
configureConsole().ignoreLocalConsole(),
when(isEquinox()).useOptions(
editConfigurationFilePut(
KARAF_FRAMEWORK, "equinox"),
systemProperty("pax.exam.framework").value(
System.getProperty("pax.exam.framework")),
//systemProperty("osgi.console").value("6666"),
//systemProperty("osgi.console.enable.builtin").value("true")
),
logLevel(WARN),
mavenBundle("org.sdo.coding", "words", "1.0")
))
container = PaxExamRuntime.createContainer(system)
container.start()
Thread.sleep(100000)
def ant = new AntBuilder()
ant.sshexec(host: "localhost",
port: '8101',
username: "smx",
password: 'smx',
trust: "yes",
command: "list",
outputproperty: 'result',
knownhosts: '/dev/null')
def result = ant.project.properties.'result'
println "result is $result"
def installed = result =~ /(?m)^(.*Installed.*)$/
println "installed ${installed[0]}"
}
Even if i increase delay i cannot find my bundle installed. I can see that the option mavenBundle doesn't affect karaf start, because if i place wrong version or artifactId, pax won't notify me about it.
Anyone has any clue on this problem?

Resources