I am in the process of converting test project from maven to gradle. The last part is to convert many maven profiles like this to gradle.
<profile>
<id>fasttrack_ui_saucelabs</id>
<properties>
<selenium.remote>true</selenium.remote>
<selenium.saucelabs>true</selenium.saucelabs>
<selenium.browser>chrome</selenium.browser>
<selenium.platform>Windows 10</selenium.platform>
<parallel.threads>4</parallel.threads>
<junit.tag>fasttrack</junit.tag>
<test.retry>2</test.retry>
</properties>
</profile>
<profile>
<id>fasttrack_login_hub</id>
<properties>
<selenium.remote>true</selenium.remote>
<selenium.saucelabs>false</selenium.saucelabs>
<selenium.browser>firefox</selenium.browser>
<parallel.threads>10</parallel.threads>
<selenium.host>selenium-test.rec.com</selenium.host>
<selenium.port>4444</selenium.port>
<junit.tag>fasttrack-login</junit.tag>
<test.retry>2</test.retry>
</properties>
</profile>
How can I convert these profiles/properties to gradle ?
You could create a plugin for each profile
Plugin<Project> fasttrack_ui_saucelabs = (Project project) -> { ... }
Plugin<Project> fasttrack_login_hub = (Project project) -> { ... }
if (condition1) apply plugin: fasttrack_ui_saucelabs
if (condition2) apply plugin: fasttrack_login_hub
Related
Blockquote
J have a Eclipse workspace with a maven parent project (parent) and child > >projects (Domain,Web,Win)
The parent pom contains the wicket-spring-boot-starter-parent
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.SteinKo.ATM</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1</version>
<packaging>pom</packaging>
<name>Parent</name>
<url>http://maven.apache.org</url>
<modules>
<module>Domain</module>
<module>Web</module>
<module>Win</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<scm>
<connection>scm:git#github.com:steinKo/ATM.git</connection>
<url>https://github.com/steinKo/ATM.git</url>
</scm>
<parent>
<!-- https://mvnrepository.com/artifact/com.giffing.wicket.spring.boot.starter/wicket-spring-boot-starter-parent -->
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId></artifactId>
<version>2.0.3</version>
</parent>
The web projects contains a Wicket pages
package steinKo.ATM;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import steinKo.ATM.presentaion.web.HomePage;
#SpringBootApplication
public class Web {
public static void main(String[] args) throws Exception {
new SpringApplicationBuilder().sources(Web.class).run(args);
}
public Class<HomePage> getHomePage() {
return HomePage.class;
}
}
package steinKo.ATM.presentaion.web;
import com.giffing.wicket.spring.boot.context.scan.WicketHomePage;
import org.apache.wicket.markup.html.WebPage;
import steinKo.ATM.domain.ATM;
import steinKo.ATM.domain.Bank;
#WicketHomePage
public class HomePage extends WebPage {
/**
*
*/
private static final long serialVersionUID = 1L;
private ATM atm;
private Bank bank;
public HomePage() {
bank = new Bank();
atm = new ATM(bank);
add(new MenuPanel("menuPanel"));
add(new ContentPanel("contentPanel", atm));
}
}
The pom.xml for the web contain dependency to wicket-spring-boot-starter
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<artifactId>Web</artifactId>
<parent>
<groupId>org.SteinKo.ATM</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1</version>
<relativePath />
</parent>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.wicket/wicket-core -->
<dependency>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter</artifactId>
</dependency>
When I execute maven test on parent project I get the message
[INFO] Scanning for projects...
[ERROR] Some problems were encountered while processing the POMs:
[ERROR] 'dependencies.dependency.version' for com.giffing.wicket.spring.boot.starter:wicket-spring-boot-starter:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 20, column 16
[ERROR] 'dependencies.dependency.version' for org.seleniumhq.selenium:selenium-java:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 28, column 13 #
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR] The project org.SteinKo.ATM:Web:0.0.1 (/Users/stein/Development/ATM/Parent/Web/pom.xml) has 2 errors
[ERROR] 'dependencies.dependency.version' for com.giffing.wicket.spring.boot.starter:wicket-spring-boot-starter:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 20, column 16
[ERROR] 'dependencies.dependency.version' for org.seleniumhq.selenium:selenium-java:jar is missing. # org.SteinKo.ATM:Web:[unknown-version], /Users/stein/Development/ATM/Parent/Web/pom.xml, line 28, column 13
[ERROR]
and
the
import com.giffing.wicket.spring.boot.context.scan.WicketHomePage; and
#WicketHomePage is marked red in the has a message "Can not be resolved"
Why?
It look like maven build issue for me dependencies.dependency.version not properly loading the dependency of com.giffing.wicket.spring.boot.starter from parent . Please build using mvn clean install from parent to all the project and fix . Its nothing to do with code .
And more over i'm not sure whether you shared your full pom add this Your pom not correct change this
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId></artifactId>
<version>2.0.3</version>
to
<dependency>
<groupId>com.giffing.wicket.spring.boot.starter</groupId>
<artifactId>wicket-spring-boot-starter</artifactId>
<version>2.0.3</version>
</dependency>
I'm having multi-project Gradle config:
-- root (folder 'gradle_test')
L--wrapper (depends on some 3rd-party maven libs)
L--module1 (depends on wrapper)
L--app
I need module1 jar (and wrapper jar as transitive dependency) to be published in local maven repo.
root build.gradle:
// for maven
ext {
groupId = 'mygroup'
version = '3.0'
}
wrapper build.gradle:
apply plugin: 'maven'
...
// maven pom
install {
repositories.mavenInstaller {
pom.groupId = rootProject.ext.groupId
pom.artifactId = 'wrapper'
pom.version = rootProject.ext.version
}
}
module1 build.gradle:
dependencies {
compile project(':wrapper')
...
}
// maven pom
install {
repositories.mavenInstaller {
pom.groupId = rootProject.ext.groupId
pom.artifactId = 'module1'
pom.version = rootProject.ext.version
}
}
Howeven when installing module1 into local maven cache i can see dependency to 'wrapper' module is generated incorrectly (version is not specified). module1 pom.xml in repo:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mygroup</groupId>
<artifactId>module1</artifactId>
<version>3.0</version>
<dependencies>
<dependency>
<groupId>gradle_test</groupId> // error 1: gradle project name (instead of overriden mvn groupId)
<artifactId>wrapper</artifactId>
<version>unspecified</version> // error 2: not set at all
<scope>compile</scope>
</dependency>
</dependencies>
</project>
In other words Gradle does not use maven module groupId/artifactId/version for maven dependencies mapped from compile project(:wrapper) declaration.
How can i do/fix it?
I had to write for wrapper and module1:
// mvn
group = rootProject.ext.groupId
version = rootProject.ext.version
and you can remove:
install {
repositories.mavenInstaller {
...
}
}
since Gradle will use project.group as mvn module groupId and project.version as mvn module version:
https://docs.gradle.org/current/userguide/maven_plugin.html#sec:maven_pom_generation
In my project I attached commons-lang3 to plugin and commons-io to project:
<build>
<plugins>
<plugin>
<groupId>#project.groupId#</groupId>
<artifactId>#project.artifactId#</artifactId>
<version>#project.version#</version>
(...)
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
Within my custom plugin (within my mojo), I can find commons-io
#Component
private MavenProject project;
(...)
project.getDependecies(); // [{groupId=commons-io, artifactId=commons-io...
How to find commons-lang3?
Using the Maven API, from the MavenProject you can get the Build instance and from it then the list of configured plugins, from each Plugin object you can then have its dependencies as following:
#Component
private PluginDescriptor pluginDescriptor;
(...)
List<Plugin> plugins = project.getBuild().getPlugins();
for (Plugin p : plugins) {
if (p.getId().equals(pluginDescriptor.getId())) {
List<Dependency> pluginDependencies = p.getDependencies();
// your logic here
break;
}
}
If you really want to cover every case, you can also scan the plugins configured in the currently active profiles as following:
List<Profile> profiles = project.getActiveProfiles();
for (Profile p : profiles) {
// from personal experience, don't forget this check!
if (p.getBuild() != null) {
checkAsShownAbove(p.getBuild().getPlugins());
}
}
Hope that helps.
As commons-lang3 is declared as a dependency only for a specific plugin, it is not available during compilation. You have to explicitly define commons-lang3 as a dependency (if its not getting included as a transitive dependency) similar to how you have defined commons-io.
I'm trying to add a listener for a service task when creating a new business process. I've found the following example:
package ru.psb.alfresco.workflow.listeners;
import org.activiti.engine.delegate.DelegateTask;
import org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener;
public class ShowDocList extends ScriptTaskListener {
private static final long serialVersionUID = 1L;
org.alfresco.repo.jscript.ScriptLogger log = new org.alfresco.repo.jscript.ScriptLogger();
#Override
public void notify(DelegateTask arg0) {
...
}
}
But eclipse doesn't know anything about the import org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener;
So what dependency do I need to add for this package? Google doesn't give me the appropriate result.
The org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener class is contained in the following artifact:
org.alfresco:org.alfresco-repository.
It is not available in maven central, but instead it can be found in the following repository:
https://maven.alfresco.com/nexus/content/groups/public/
So in your pom you would need to add the following:
<project>
...
<repositories>
...
<!-- define the alfresco maven repository -->
<repository>
<id>Alfresco Maven Repository</id>
<url>https://maven.alfresco.com/nexus/content/groups/public/</url>
</repository>
...
</repositories>
...
<dependencies>
<!-- add dependency to alfresco-repository -->
<dependency>
<groupId>org.alfresco</groupId>
<artifactId>alfresco-repository</artifactId>
<version>5.0.c</version>
</dependency>
</dependencies>
...
</project>
Given a Gradle web project that is to be published as a JAR (so that it can be a dependency of another Gradle web project, which has a different release cycle).
The maven-publish plugin is used:
apply plugin: 'war'
apply plugin: 'maven'
apply plugin: 'maven-publish'
The web project has a providedCompile dependency:
providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
A jar is published using mavenJava:
publishing {
publications {
// mavenJava publishes a jar file
mavenJava(MavenPublication) {
from components.java
}
}
repositories {
mavenLocal()
}
}
The problem is that javax.servlet-api has a runtime scope in the resulting Maven POM:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>runtime</scope>
</dependency>
Runtime scope makes no sense for the servlet-api, it is even harmful. How can the scope be set to provided in the pom.xml?
With the help of pom.withXml (see this Gradle sample) it's possible to transform Gradle's providedCompile into provided scope for Maven's POM:
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// providedCompile -> provided scope
pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.providedCompile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope*.value = 'provided'
}
}
}
}
repositories {
mavenLocal()
}
}
What the pom.withXml section does is going through all dependencies of type providedCompile within the Gradle project configuration and changing the scope to be written into the Maven pom.xml from runtime to provided.
The generated pom.xml now has the provided scope set for the javax.servlet-api:
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
[...]
<dependencies>
[...]
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>