我已经使用新的Maven Publisher插件配置了Gradle来发布项目工件,遗憾的是这个插件在生成中存在pom.xml
依赖性问题- 依赖项具有范围runtime
而不是compile
.
我的配置是这样的:
apply plugin: 'maven-publish'
publishing {
publications {
mavenCustom(MavenPublication) {
from components.java
}
}
repositories {
maven {
url "https://api.bintray.com/maven/codearte/public/fairyland"
credentials {
username = bintrayUser
password = bintrayKey
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用一个命令发布很简单:
gradle publish
Run Code Online (Sandbox Code Playgroud)
如何以旧的(工作)方式实现这一目标?项目发布时是否可以自动化项目分页?
我的自定义maven插件有三个目标(mojos):
convert
分配到默认阶段: process-test-resources
generateStubs
分配到默认阶段: package
generateTests
分配到默认阶段: generate-test-sources
如何将这三个mojo绑定到默认的生命周期阶段,这样用户可以简单地使用插件而无需特殊配置和项目的任何更改packaging
?
用户应该简单地添加:
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<extensions>true</extensions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
代替
<plugin>
<groupId>io.codearte.accurest</groupId>
<artifactId>accurest-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>convert</goal>
<goal>generateStubs</goal>
<goal>generateTests</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我可以通过components.xml
以下方式实现这一点,但这需要一些丑陋的黑客(指定不存在阶段 - ugly-fix
)并且我不确定,如果此解决方案在所有情况下都能正常工作.
<component-set>
<components>
<component>
<role>org.apache.maven.lifecycle.Lifecycle</role>
<implementation>org.apache.maven.lifecycle.Lifecycle</implementation>
<role-hint>accurest</role-hint>
<configuration>
<id>accurest</id>
<phases>
<phase>ugly-fix</phase> // plugin fail without this
</phases>
<default-phases>
<process-test-resources>
io.codearte.accurest:accurest-maven-plugin:${project.version}:convert
</process-test-resources>
<generate-test-sources>
io.codearte.accurest:accurest-maven-plugin:${project.version}:generateTests
</generate-test-sources>
<package>
io.codearte.accurest:accurest-maven-plugin:${project.version}:generateStubs
</package>
</default-phases>
</configuration>
</component>
</components>
</component-set>
Run Code Online (Sandbox Code Playgroud)
它是否正确?是更好的方法来做这样的配置?
更多信息:
如何在仅使用WebApplicationInitializer的 java中以编程方式指定Web应用程序(war)的显示名称.我有类似的东西
public class WebAppInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext servletContext) throws ServletException {
...
}
}
Run Code Online (Sandbox Code Playgroud)
有了web.xml
这个看起来像这样:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="false">
<display-name>my app</display-name>
...
</web-app>
Run Code Online (Sandbox Code Playgroud)
这在Java配置中是否可行?
样品测试
@Test
public void should_be_equals(){
LocalDate now = new LocalDate(2015,01,29);
assertThat(now.plusMonths(1).plusMonths(1)).isEqualTo(now.plusMonths(2));
}
Run Code Online (Sandbox Code Playgroud)
奇怪的结果:
org.junit.ComparisonFailure:
Expected :2015-03-29
Actual :2015-03-28
Run Code Online (Sandbox Code Playgroud)
为何这有所不同?
我已经扩展了spring security oauth示例social-auth-server,linkedIn被添加为第三个身份验证选项.托管授权服务器的教程中介绍了此项目.
源代码:https://github.com/spring-guides/tut-spring-boot-oauth2/tree/master/auth-server
如何配置此客户端以添加client_id?
LinkedIn属性:
linkedin:
client:
clientId: XXX
clientSecret: YYY
accessTokenUri: https://www.linkedin.com/oauth/v2/accessToken
userAuthorizationUri: https://www.linkedin.com/oauth/v2/authorization
resource:
userInfoUri: https://api.linkedin.com/v1/people/~?format=json
Run Code Online (Sandbox Code Playgroud)
日志:
uth2ClientAuthenticationProcessingFilter : Request is to process authentication
g.c.AuthorizationCodeAccessTokenProvider : Retrieving token from https://www.linkedin.com/oauth/v2/accessToken
g.c.AuthorizationCodeAccessTokenProvider : Encoding and sending form: {grant_type=[authorization_code], code=[XXXXXXXXXXXXXXXXXXXX], redirect_uri=[http://localhost:8080/login/linkedin]}
uth2ClientAuthenticationProcessingFilter : Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Could not obtain access token
Run Code Online (Sandbox Code Playgroud)
例外:
org.springframework.security.authentication.BadCredentialsException: Could not obtain access token
at org.springframework.security.oauth2.client.filter.OAuth2ClientAuthenticationProcessingFilter.attemptAuthentication(OAuth2ClientAuthenticationProcessingFilter.java:107) ~[spring-security-oauth2-2.0.13.RELEASE.jar:na]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-4.2.2.RELEASE.jar:4.2.2.RELEASE]
at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:112) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73) [spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at …
Run Code Online (Sandbox Code Playgroud) 为什么@InjectMocks
这种测试可能会避免这种情况.
@RunWith(MockitoJUnitRunner.class)
public class MyClassTest {
@Mock
private Bar bar;
@InjectMocks
private Foo foo; // created by Mockito
@Test
public void shouldCallMethod() {
// when
foo.myMethod();
// then
...
}
}
Run Code Online (Sandbox Code Playgroud)
Foo.java
public class Foo {
private final Bar bar;
public Foo(Bar bar) {
this.bar = bar;
}
...
Run Code Online (Sandbox Code Playgroud)
我在对这个答案的评论中读到了这个:https://stackoverflow.com/a/21172873/516167
标记应在其上执行注射的区域.
- 允许速记模拟和间谍注射.
- 最大限度地减少重复模拟和间谍注射.
参考:@InjectMocks JavaDoc.
我一直在尝试使用IntelliJ IDEA中的Spock测试创建一个Groovy项目.
以下是我遵循的步骤:
Groovyc: Cannot compile Groovy files: no Groovy library is defined for module...
我可能错过了一些东西,因为我厌倦了在一半的时间里尝试不同的配置.
我希望通过org.glassfish.jersey
实施向Json推广
Map<String, String> entity = Maps.newHashMap();
entity.put("foo", "bar");
Response response = Response.status(Response.Status.OK)
.entity(entity)
.type(MediaType.APPLICATION_JSON).build();
System.out.println(response.getEntity());
Run Code Online (Sandbox Code Playgroud)
此地图序列化为非标准{ foo: "bar" }
.我想在单元测试中测试这种行为.
标准 UUID 很长,您无法通过双击选择整个内容。
例如 123e4567-e89b-12d3-a456-426655440000
我喜欢较短的 ID。
我喜欢能够双击一个 ID 来选择它。
我的问题是:将标准 ID 编码为 22(ish) 个字符长的 base62 字母数字字符串是否有任何问题?
例如 71jbvv7LfRKYp19gtRLtkn
编辑:添加上下文
我们的需求是在 NoSQL 数据存储服务(如 DynamoDB)中存储一般数据。碰撞不应该发生,但我的理解是与 UUID 的碰撞风险可以忽略不计。标准 UUID 将满足我们的需求,所以我要问的是......在 base62 中编码是否存在标准 UUID 不存在的任何差异、额外风险或不可预见的问题?
谢谢。
java ×5
maven ×2
base62 ×1
bintray ×1
date ×1
email ×1
gradle ×1
groovy ×1
java-ee ×1
jax-rs ×1
jersey ×1
jersey-2.0 ×1
jodatime ×1
json ×1
maven-3 ×1
maven-plugin ×1
mockito ×1
oauth ×1
pom.xml ×1
publish ×1
release ×1
servlets ×1
spock ×1
spring ×1
time ×1
unit-testing ×1
uuid ×1
web ×1
web.xml ×1