如何在Gradle中忽略特定的传递依赖?
例如,许多库(例如Spring和...)依赖于commons-logging,我想commons-logging用SLF4J(和它的jcl-over-slf4j桥)替换.
我的gradle脚本中是否有任何提及它的方式,而不是依赖于每个依赖的依赖commons-logging?
我在考虑一个脚本,迭代所有依赖项并在所有依赖项上添加一些exclude,是否有更好的解决方案?那个剧本怎么样?
假设有以下实体(不写JPA注解):
class Questionnaire {
...
}
class Policy {
private Questionnaire questionnaire;
...
}
class LifeQuestionnaire extends Questionnaire {
private String someField;
}
class LifePolicy extends Policy {
...
}
Run Code Online (Sandbox Code Playgroud)
看起来政策引用了调查问卷,但 aLifePolicy引用了LifeQuestionnaire(此限制始终正确)。
有什么办法可以编写这样的查询:
from LifePolicy lplc
where ((LifeQuestionnaire) lplc.questionnaire).someField = :fieldValue
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我希望在 HQL 查询中进行某种类型的转换,因为someField仅在LifeQuestionnaire.
我已经定义了一个简单的任务
task printCompileTestLib {
configurations.testCompile.each { println it }
}
test.dependsOn(printCompileTestLib)
Run Code Online (Sandbox Code Playgroud)
但是当我执行任务后发生以下错误:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\projects\fwk\trunk-gradle\ext\build.gradle' line: 2
* What went wrong:
A problem occurred evaluating project ':ext'.
> You can't change a configuration which is not in unresolved state!
* Try:
Run with --debug option to get more log output.
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating project ':ext'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:132)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:38)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:25)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55) …Run Code Online (Sandbox Code Playgroud) 我有以下Spring Boot示例应用程序。疯狂的事情是,如果我@EnableMongoAuditing在SampleApplication bean上添加注释,则lastModifiedDate不会被填充createDate。这是为什么?我在网上搜索,许多人createDate在更新过程中出现清空问题,但是我没有更新。
文件类别:
@Document
public class SampleBean implements Persistable<String> {
@Id
public String id;
@CreatedDate
public LocalDateTime createDate;
@LastModifiedDate
public LocalDateTime lastModifiedDate;
public String name;
@Override
public String getId() {
return id;
}
@Override
public boolean isNew() {
return id != null;
}
}
Run Code Online (Sandbox Code Playgroud)
仓库接口:
@Repository
public interface SampleBeanRepository extends MongoRepository<SampleBean, String> {
}
Run Code Online (Sandbox Code Playgroud)
休息控制器:
@RestController
public class WebService {
@Autowired
private SampleBeanRepository repository;
@RequestMapping("/insert")
public String insert() {
SampleBean sampleBean …Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 1.5.9.RELEASE 开发一个应用程序,并且使用 Gradle 作为构建工具。
我想在项目中使用SelenumHQ 3.8.1。
当我构建项目时,我注意到Selenium 2.53.1被添加到项目中(而不是3.8.1),所以我调查并找出了原因。
我的build.gradle中存在以下语句:
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:1.5.9.RELEASE")
}
}
Run Code Online (Sandbox Code Playgroud)
并在该文件中 selenium.version 属性设置为“2.53.1”。
所以我将声明更改为
dependencyManagement {
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:1.5.9.RELEASE") {
bomProperty 'selenium.version', '3.8.1'
}
}
}
Run Code Online (Sandbox Code Playgroud)
但现在 IDEA 将 3.8.1 和 2.53.1 显示为项目的依赖项,当我使用 gradle 构建工件时,只存在 2.53.1 依赖项,没有 3.8.1 的迹象。
如何更改此行为并使用 Selenium 3.8.1?
PS Selenium是由多个jar文件组成的,所以它不仅仅是一个Jar文件,我想使用gradle以最小化的方式更新所有这些文件。
在Java Concurrency in Practice中有一个让我困惑的样本:
public class Novisibility {
private static boolean ready;
private static int number;
private static class ReaderThread implements Runnable {
public void run() {
while (!ready) {
Thread.yield();
}
System.out.println(number);
}
}
public static void main(String[] args) {
System.out.println("0");
new Thread(new ReaderThread()).run();
System.out.println("1");
number = 42;
System.out.println("2");
ready = true;
System.out.println("3");
}
}
Run Code Online (Sandbox Code Playgroud)
我可以理解重新排序使循环永不中断,但我无法理解为什么"1","2"和"3"永远不会打印到控制台.身体有帮助吗?
执行以下代码时我很困惑:
@Test
public void testAccessible() throws NoSuchMethodException {
Constructor<LinkedList> constructor = LinkedList.class.getConstructor();
Assert.assertTrue(constructor.isAccessible());
}
Run Code Online (Sandbox Code Playgroud)
断言失败,但LinkedList类有public默认构造函数.那么为什么isAccessible()返回false?
我们在项目中使用Oracle数据库.我们定义了可以应用于数据库的约束(包括主要,唯一,检查和外键约束).
似乎定义约束DEFERRABLE允许我们在需要时对它们进行DEFER,那么为什么要将任何约束定义为NOT DEFERRABLE?
为什么像Oracle这样的数据库没有DEFERRABLE作为默认情况?
是否有任何专业人士来定义一个不可延伸的约束?
我正在尝试以下代码:http://www.dineshonjava.com/2012/12/spring-mvc-with-hibernate-crud-example.html#.Uus0bvnoSGc sdnext-servlet.xml如下
<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<context:property-placeholder location="classpath:resources/database.properties">
</context:property-placeholder>
<context:component-scan base-package="com.dineshonjava">
</context:component-scan>
<tx:annotation-driven transaction-manager="hibernateTransactionManager">
</tx:annotation-driven>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="jspViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/views/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">
<property name="driverClassName" value="${database.driver}"></property>
<property name="url" value="${database.url}"></property>
<property name="username" value="${database.user}"></property>
<property name="password" value="${database.password}"></property>
</bean>
<bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<list>
<value>com.dineshonjava.model.Employee</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto} </prop>
</props>
</property>
</bean> …Run Code Online (Sandbox Code Playgroud) 我有一个项目,由 junit 4 和 5 实现测试。有些测试需要存在数据库,有什么方法可以标记这些特定测试(TestSuite 是答案吗?),所以 gradle 继续构建,即使那些测试失败了?
我不想跳过其他测试,而只想跳过这些特定测试。
我使用的是 junit 5 vintage,所以我的测试任务同时运行 junit 4 和 junit 5 测试。
我需要编写一个PL/SQL过程,在这个过程中我需要在自己的事务边界内调用另一个过程,并且无论主事务的失败或提交如何都要提交它.换句话说,我需要像REQUIRES NEW事务传播这样的东西.
就像是:
procedure mainProcedure(arugements) is
begin
// some statements
nestedProcedure(someArguments);
// some other statements
end;
procedure nestedProcedure(arguments) is
begin
// start a new transaction
// some statements, lock some objects!
// commit the new transaction and release locked objects
end;
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我正在将项目构建从 ANT 移植到 Gradle。除了混淆部分外,一切都已完成,混淆任务如下build.xml:
<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${ant.yguard.path}"/>
<target name="obfuscate-no-test" depends="no-test-jar">
<yguard>
<inoutpairs>
<fileset dir="${dir.dist}">
<include name="**/*.jar"/>
<exclude name="**/*_obf.jar"/>
<exclude name="**/*-doc.jar"/>
</fileset>
</inoutpairs>
<externalclasses>
<path refid="path.lib.biz"/>
<path refid="path.lib.share"/>
<path refid="path.lib.web"/>
</externalclasses>
<rename logfile="${rename.log}">
<property name="naming-scheme" value="best"/>
<keep>
<class classes="none" fields="none" methods="none">
<patternset>
<include name="com.payeshgaran.framework.internal.**.*"/>
</patternset>
</class>
<class classes="public" fields="protected" methods="protected">
<patternset>
<include name="com.payeshgaran.framework.**.*"/>
<exclude name="com.payeshgaran.framework.internal.**.*"/>
</patternset>
</class>
</keep>
<adjust replacecontent="true">
<include name="META-INF/*.tld"/>
</adjust>
</rename>
</yguard>
</target>
Run Code Online (Sandbox Code Playgroud)
为了将其移植到 gradle,我这样做了:
task obfuscate(dependsOn: [":ext:build", ":biz:build", ":web:build"]) {
ant.taskdef(name: "yguard",
classname: "com.yworks.yguard.YGuardTask", …Run Code Online (Sandbox Code Playgroud) gradle ×5
java ×4
hibernate ×2
oracle ×2
spring-boot ×2
ant ×1
auditing ×1
concurrency ×1
constraints ×1
groovy ×1
hql ×1
jpa ×1
junit ×1
junit4 ×1
junit5 ×1
maven ×1
maven-bom ×1
obfuscation ×1
osgi ×1
plsql ×1
reflection ×1
selenium ×1
spring ×1
spring-data ×1
spring-mvc ×1
sql ×1
transactions ×1
xml ×1
yguard ×1