Could not resolve all dependencies for configuration [custom configuration] - gradle

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

Related

FileNotFoundException: `generated/source/apollo/generatedIR/main`

I try to generate my graphql schema using gradle apollo generateApolloClasses. So the first step is to generateMainApolloIR and it is working fine. It is generating a MainAPI.json under
/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/MainAPI.json. But the generateApolloClasses is failing with:
> java.io.FileNotFoundException: /Users/mctigg/Documents/Repositories/generated/source/apollo/generatedIR/main (Is a directory)
So it is looking into the wrong path! This is my gradle config:
apollo {
nullableValueType = "javaOptional"
outputPackageName = "generated.client.backend"
}
task generateBackendSchemaJson(type: ApolloSchemaIntrospectionTask) {
url = 'src/main/graphql/client/backend/schema.graphqls'
output = 'src/main/graphql/client/backend/schema.json'
}
tasks.findByName('generateMainApolloIR').dependsOn(['generateBackendSchemaJson'])
So how can I configure generateApolloClasses to look into:
/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/
Instead of
/generated/source/apollo/generatedIR/main/
May be you should set schema file path as follows:
apollo {
schemaFilePath = "/generated/source/apollo/generatedIR/main/src/main/graphql/client/backend/schema.json"
nullableValueType = "javaOptional"
outputPackageName = "generated.client.backend"
}

SonarQube - specify location of sonar.properties

I'm trying to deploy SonarQube on Kubernetes using configMaps.
The latest 7.1 image I use has a config in sonar.properties embedded in $SONARQUBE_HOME/conf/ . The directory is not empty and contain also a wrapper.conf file.
I would like to mount the configMap inside my container in a other location than /opt/sonar/conf/ and specify to sonarQube the new path to read the properties.
Is there a way to do that ? (environment variable ? JVM argument ? ...)
It is not recommended to modify this standard configuration in any way. But we can have a look at the SonarQube sourcecode. In this file you can find this code for reading the configuration file:
private static Properties loadPropertiesFile(File homeDir) {
Properties p = new Properties();
File propsFile = new File(homeDir, "conf/sonar.properties");
if (propsFile.exists()) {
...
} else {
LoggerFactory.getLogger(AppSettingsLoaderImpl.class).warn("Configuration file not found: {}", propsFile);
}
return p;
}
So the conf-path and filename is hard coded and you get a warning if the file does not exist. The home directory is found this way:
private static File detectHomeDir() {
try {
File appJar = new File(Class.forName("org.sonar.application.App").getProtectionDomain().getCodeSource().getLocation().toURI());
return appJar.getParentFile().getParentFile();
} catch (...) {
...
}
So this can also not be changed. The code above is used here:
#Override
public AppSettings load() {
Properties p = loadPropertiesFile(homeDir);
p.putAll(CommandLineParser.parseArguments(cliArguments));
p.setProperty(PATH_HOME.getKey(), homeDir.getAbsolutePath());
p = ConfigurationUtils.interpolateVariables(p, System.getenv());
....
}
This suggests that you can use commandline parameters or environment variables in order to change your settings.
For my problem, I defined environment variable to configure database settings in my Kubernetes deployment :
env:
- name: SONARQUBE_JDBC_URL
value: jdbc:sqlserver://mydb:1433;databaseName=sonarqube
- name: SONARQUBE_JDBC_USERNAME
value: sonarqube
- name: SONARQUBE_JDBC_PASSWORD
valueFrom:
secretKeyRef:
name: sonarsecret
key: dbpassword
I needed to use also ldap plugin but it was not possible to configure environment variable in this case. As /opt/sonarqube/conf/ is not empty, I can't use configMap to decouple configuration from image content. So, I build my own sonarqube image adding the ldap jar plugin and ldap setting in sonar.properties :
# General Configuration
sonar.security.realm=LDAP
ldap.url=ldap://myldap:389
ldap.bindDn=CN=mysa=_ServicesAccounts,OU=Users,OU=SVC,DC=net
ldap.bindPassword=****
# User Configuration
ldap.user.baseDn=OU=Users,OU=SVC,DC=net
ldap.user.request=(&(sAMAccountName={0})(objectclass=user))
ldap.user.realNameAttribute=cn
ldap.user.emailAttribute=mail
# Group Configuration
ldap.group.baseDn=OU=Users,OU=SVC,DC=net
ldap.group.request=(&(objectClass=group)(member={dn}))

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"

gradle error "Cannot convert the provided notation to a File or URI"

I have defined two system properties in gradle.properties:
systemProp.buildDir=build
systemProp.cfgDir=build\\cfg
And I have the following task defined in build.gradle:
task clean(group:'clean',description:'clean the project') << {
ant.sequential {
delete(dir: System.properties.buildDir)
mkdir(dir: System.properties.buildDir)
delete(dir: System.properties.cfgDir)
mkdir(dir: System.properties.cfgDir)
}
}
This generates the following error:
Execution failed for task ':clean'.
> Cannot convert the provided notation to a File or URI: {dir=build}.
The following types/formats are supported:
- A String or CharSequence path, e.g 'src/main/java' or '/usr/include'
- A String or CharSequence URI, e.g 'file:/usr/include'
- A File instance.
- A URI or URL instance.
But this equivalent block of code does not generate any error and works as expected:
task clean(group:'clean',description:'clean the project') << {
ant.delete(dir: System.properties.buildDir)
ant.mkdir(dir: System.properties.buildDir)
ant.delete(dir: System.properties.cfgDir)
ant.mkdir(dir: System.properties.cfgDir)
}
Is the error on the first syntax a bug in gradle, or am I missing something?
This error is caused by the fact that your Gradle build script delegates to an instance of the Project interface, which also has a method called delete, whose argument is evaluated by Project.file(). If you want to use the Ant task you'll have to qualify it with the ant prefix.

Aether, get artifact from local repo

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.

Resources