首页 » 文章

maven 中如果一个module以来另一个模块的test class,需要使用maven-jar-plugin和classifier(最新的用type代替了)

1.项目a(被b以来的test class)

<project>
  <build>
    <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-jar-plugin</artifactId>
       <version>2.4</version>
       <executions>
         <execution>
           <goals>
             <goal>test-jar</goal>
           </goals>
         </execution>
       </executions>
     </plugin>
    </plugins>
  </build>
</project>

2.项目b,以来a中的test calss

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.myco.app</groupId>
      <artifactId>foo</artifactId>
      <version>1.0-SNAPSHOT</version>
      <type>test-jar</type>
      <scope>test</scope>
    </dependency>
  </dependencies>
  ...
</project> 

gradle项目越来越多,但是公司项目只能用maven,转换方法如下

1.每个项目的build.gradle(或者gradle.kts)加入插件

groovy:

plugins {
    id 'maven'
}

kotlin

plugins {
    maven
}

2.加入task

groovy


task writeNewPom {
    doLast {
        pom {
            project {
                inceptionYear '2008'
                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }
            }
        }.writeTo("$buildDir/newpom.xml")
    }
}

kotlin

task("writeNewPom") {
    doLast {
        maven.pom {
            withGroovyBuilder {
                "project" {
                    setProperty("inceptionYear", "2008")
                    "licenses" {
                        "license" {
                            setProperty("name", "The Apache Software License, Version 2.0")
                            setProperty("url", "http://www.apache.org/licenses/LICENSE-2.0.txt")
                            setProperty("distribution", "repo")
                        }
                    }
                }
            }
        }.writeTo("$buildDir/newpom.xml")
    }
}

3.gradle writeNewPom 运行即可

spring boot 引入swagger可以方便的测试api和查看api文档
1.引入依赖
 <!-- Swagger -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>
 
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>

2.加入SwaggerConfig.java

package tv.rr.panther.base.config;
 
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import tv.rr.panther.base.util.PropertiesUtil;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * @title
 * @description
 * @usage

 * @author shenfeng
 * @create 2018/2/12 10:14
 */
 
@Profile({"dev","qtest"})
 
@Configuration
@EnableSwagger2
@ComponentScan
@EnableWebMvc
public class SwaggerConfig {
 
    private static final String SWAGGER_FLAG = PropertiesUtil.getPropertyValue("application", "swagger.enable");
 
    @Bean
    public Docket api(){
        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .enable(true)
                .globalOperationParameters(getGlobalHeaderParameters())
                .apiInfo(apiInfo());
    }
 
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("拍客")
                .description("paike接口文档")
                .version("1.0.0")
                .build();
    }
 
    private List<Parameter> getGlobalHeaderParameters() {
        ParameterBuilder parameterBuilder = new ParameterBuilder();
        List<Parameter> parameters = new ArrayList<>(3);
        parameterBuilder.name("appId").description("客户端version_Platform")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("3.7.0_ios");
 
        parameterBuilder.name("token").description("客户端version_Platform")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("a261fdc8ddab4e8b8b233d9d011da442");
 
        parameters.add(parameterBuilder.build());
        parameterBuilder.name("sign").description("客户端签名md5(timestamp+token+appId)")
                .modelRef(new ModelRef("string"))
                .parameterType("header").required(true).defaultValue("md5(12132345645_token_3.7.2_ios)");
        parameters.add(parameterBuilder.build());
        return parameters;
    }
 
}

3.在controller上贴注解吧

package tv.rr.panther.controller;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tv.rr.panther.base.controller.BaseController;
import tv.rr.panther.base.view.CommonResult;
import tv.rr.panther.responseData.tag.SelectTagListResponseData;
import tv.rr.panther.responseData.tag.TagListResponseData;
import tv.rr.panther.service.TagService;
import tv.rr.panther.view.TagView;
import tv.rr.panther.view.TagViewNoPic;
 
import java.util.List;
 
/**
 * @title
 * @description
 * @usage
 * @author shenfeng
 * @create 4/28/2018 3:36 PM
 *
 *                             _ooOoo_
 *                            o8888888o
 *                            88" . "88
 *                            (| -_- |)
 *                            O\  =  /O
 *                         ____/`---'\____
 *                       .'  \\|     |//  `.
 *                      /  \\|||  :  |||//  \
 *                     /  _||||| -:- |||||-  \
 *                     |   | \\\  -  /// |   |
 *                     | \_|  ''\---/''  |   |
 *                     \  .-\__  `-`  ___/-. /
 *                   ___`. .'  /--.--\  `. . __
 *                ."" '<  `.___\_<|>_/___.'  >'"".
 *               | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *               \  \ `-.   \_ __\ /__ _/   .-` /  /
 *          ======`-.____`-.___\_____/___.-`____.-'======
 *                             `=---='
 *          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 *                     佛祖保佑        永无BUG
 */
@RequestMapping("tag")
@Api
@Controller
public class TagController extends BaseController {
 
    @Autowired
    private TagService tagService;
 
    @RequestMapping("recommendList")
    @ApiOperation(value = "首页推荐标签列表",httpMethod = "GET")
    @ResponseBody
    public CommonResult<TagListResponseData> recommondList(){
        CommonResult<TagListResponseData> result = CommonResult.getInstance();
        TagListResponseData tagListResponseData = new TagListResponseData();
        List<TagView> list = tagService.recommendList();
        tagListResponseData.setTagList(list);
        result.setData(tagListResponseData);
        return result;
    }
 
    /**
     * 可选列表,目前是所有的
     * @return
     */
    @RequestMapping("selectList")
    @ApiOperation(value = "视频可选标签",httpMethod = "GET")
    @ResponseBody
    public CommonResult<SelectTagListResponseData> selectList(){
        CommonResult<SelectTagListResponseData> result = CommonResult.getInstance();
 
        SelectTagListResponseData selectTagListResponseData = new SelectTagListResponseData();
 
        List<TagViewNoPic> list = tagService.allList();
        selectTagListResponseData.setTagList(list);
        result.setData(selectTagListResponseData);
 
        return result;
    }
 
}
  1. WebAppConfig 中web mvc注册路径
package tv.rr.panther.base.config;
 
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
/**
 * @title
 * @description
 * @usage
 * @author shenfeng
 * @create 2018/2/12 10:19
 */
@Profile({"dev","qtest"})
@Configuration
@EnableWebMvc
public class WebAppConfig extends WebMvcConfigurerAdapter {
 
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
 
}

windows 下启动mysql比较麻烦,用命令行安装成mysql服务,然后启动服务来运行mysql

1.首先下载解压mysql--- https://dev.mysql.com/downloads/mysql/ ,解压后在根目录下创建mysql.ini,注意这里好多教程都没说明,路径要用双引号,否则win10报错

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8 
[mysqld]
# 设置3306端口
port = 3306 
# 设置mysql的安装目录
basedir="E:\\baiduDown\\mysql-5.7.29-winx64"
datadir="E:\\baiduDown\\mysql-5.7.29-winx64\\data"
# 允许最大连接数
max_connections=200
# 设置mysql服务端默认字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB 
# 注意这个参数,MySQL默认值导致在Windows 10 专业版上无法安装
innodb_flush_method=normal

2.管理员模式命令行执行下面的指令,注意执行的路径必须是mysql所在路径

mysqld.exe --initialize-insecure  --explicit_defaults_for_timestamp
mysqld.exe --install 

3.启动mysql服务

net start mysql

目前遇到一个需求,需要用fiddler抓取idea插件的http请求。

解决办法,在idea64.exe.vmoptions和idea.exe.vmoptions加入下面的配置


-DproxySet=true
-Dhttp.proxyHost=127.0.0.1
-Dhttp.proxyPort=8888